BTicino smarther thermostat


(twiggo) #1

Hi all do you know how can i integrate BTicino smarther thermostat in openhab?
https://www.smarther.bticino.it

There s some bindings or stuff like that… and idea??

Thanks

Twiggo


(Rich Koshak) #2

Search is pretty helpful.

https://docs.openhab.org/search?q=BTicino


(twiggo) #3

Yes but noone says about this thermostat…only BTicino in general
Or never find something about…is it right? Do you have any idea?


(Rich Koshak) #4

Like it says in the documents:

Use 4 for the “who” field in the binding config for the Item to tell it you are controlling Temperature and it provides a link to the OpenWebNet documentation which tells you what to put into the “what” and “where” fields.


(twiggo) #5

Thanks rlkoshak.

In bindings says : Prerequisites
To access your Bticino My Home bus you need an IP gateway (like e.g. the MH200N, F453, F454)

I have no IP gateway…only thermostat, do you have an idea?

Thanks 4 your help!


(Rich Koshak) #6

You will have to purchase an IP gateway.


(Massimo) #7

Unfortunately in the official BTicino forum it is said that Smarther (product code X8000) does NOT support the OpenWebNet protocol, therefore apparently there is no way to integrate it with OpenHAB or anything else.
No Local or remote API are supported (at least officially…).
So buying an IP gateway from BTciino would not solve the problem.
See: https://www.myopen-legrandgroup.com/forums/topic/x8000-openwebnet-2/
Massi


(twiggo) #8

hi massi, really really thanks…


(Arnaud) #9

Hello,
New website for developpers.


(twiggo) #10

So is it work without a gateway? Don’t understand…


(Francesco Ranieri) #11

I managed to integrate smarther via api into a home assistant without a gateway


(Massimo) #12

can you provide more information?
did you use cloud APIs or local (reverse-engineered?) APIs ?
is the code available on some repo ?

bye
M


(Francesco Ranieri) #13

No reverse Enginering. I use legrand’ api
Developper API Portal Legrand

You must enable third-party access in the mobile app using the developer account created within the legrand portal.

FAQ

#!/bin/bash
. /home/pi/scripts/lib/myfunctions.sh

log "Inizio"

clientid="via mail by legrand after registration app"
client_secret="via mail by legrand after registration app"
plantid="via web portal by api"
moduleid="via web portal by api"
grant_type="refresh_token"
refresh_token=""


log "Parametri Utilizzati per la chiamata"
log "Utilizzo i seguenti parametri per effettuare la chiamata."
log "clientid: $clientid"
log "client_secret: $client_secret"
log "plantid: $plantid"
log "moduleid: $moduleid"
log "grant_type: $grant_type"
log "refresh_token: $refresh_token"


log "L'access token ha durata di 1 ora"
log "Verifico se è necessario richiedere un nuovo access token"


timestamp_now=`date +%s`
timestamp_expiry_access_token=`less /home/pi/scripts/smarther/refresh.json | jq -r .expires_on`
timestamp_now_2_date=`date -d "@$timestamp_now"`
timestamp_expiry_access_token_2_date=`date -d "@$timestamp_expiry_access_token"`

accesstoken=""




if [ $timestamp_expiry_access_token -gt $timestamp_now ]; then
   log "Access Token ancora valido."
   log "Data Expiry Token $timestamp_expiry_access_token_2_date maggiore rispetto alla data attuale $timestamp_now_2_date"
   accesstoken=`less /home/pi/scripts/smarther/refresh.json | jq -r .access_token`
   
   log "####################################################################"
   log "####################################################################"
   log "Access Token:$accesstoken"
   log "####################################################################"
   log "####################################################################"
   log "Scadenza Access Token: $timestamp_expiry_access_token_2_date"
   log "####################################################################"
   log "####################################################################"
   
else
   log "Access Token non più valido. E' necessario richiedere un nuovo token."
   log "Data Expiry Token $timestamp_expiry_access_token_2_date raggiunta rispetto alla data attuale $timestamp_now_2_date"
   log "Eseguo la chiamata per il recupero del nuovo access token"
   curl --silent -X POST -d "client_id=$clientid&client_secret=$client_secret&grant_type=$grant_type&refresh_token=$refresh_token" https://partners-login.eliotbylegrand.com/token  > /home/pi/scripts/smarther/refresh.tmp
   sleep 5
   less /home/pi/scripts/smarther/refresh.tmp | jq '.' | more > /home/pi/scripts/smarther/refresh.json
   accesstoken=`less /home/pi/scripts/smarther/refresh.json | jq -r .access_token`
   refrehtoken=`less /home/pi/scripts/smarther/refresh.json | jq -r .refresh_token`
   
   timestamp_expiry_access_token=`less /home/pi/scripts/smarther/refresh.json | jq -r .expires_on`
   timestamp_expiry_access_token_2_date=`date -d "@$timestamp_expiry_access_token"`
   
   log "####################################################################"
   log "####################################################################"
   log "Nuovo Access Token:$accesstoken"
   log "####################################################################"
   log "####################################################################"
   log "Nuova Scadenza Access Tokem: $timestamp_expiry_access_token_2_date"
   log "####################################################################"
   log "####################################################################"
   log "Nuovo Refresh Token: $refrehtoken"
   log "####################################################################"
   log "####################################################################"
   
   
   

fi


key="via web portal by legrand"
ocm="Bearer $accesstoken"



case $1 in
     get_info)
	      log "Procedura richiamata con parametro $1"
          curl -v -X GET "https://api.developer.legrand.com/smarther/v1.0/chronothermostat/thermoregulation/addressLocation/plants/$plantid/modules/parameter/id/value/$moduleid/measures" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $key" -H "Authorization: $ocm" > /home/pi/scripts/smarther/getInfo.tmp
          less /home/pi/scripts/smarther/getInfo.tmp | jq '.' | more > /home/pi/scripts/smarther/getInfo.json
		  log "Informazioni Recuperate. Controllare il file getInfo.json."
		  
		  ;;
	 get_status)
	      log "Procedura richiamata con parametro $1"
          curl -v -X GET "https://api.developer.legrand.com/smarther/v1.0/chronothermostat/thermoregulation/addressLocation/plants/$plantid/modules/parameter/id/value/$moduleid" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $key" -H "Authorization: $ocm" > /home/pi/scripts/smarther/get_status.tmp
          less /home/pi/scripts/smarther/get_status.tmp | jq '.' | more > /home/pi/scripts/smarther/get_status.json
		  log "Informazioni Recuperate. Controllare il file get_status.json."
		  ;;	  
		  
		  
     set_protection_mode)
	      log "Procedura richiamata con parametro $1"
          curl  -v -X POST "https://api.developer.legrand.com/smarther/v1.0/chronothermostat/thermoregulation/addressLocation/plants/$plantid/modules/parameter/id/value/$moduleid" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $key" -H "Authorization: $ocm" --data-ascii "{\"function\": \"heating\", \"mode\": \"protection\"}"
		  log "Protection Mode Impostatato sul termostato."
		  sleep 5
		  log "Aggiornamento Stato...."
		  curl --silent -X GET "https://api.developer.legrand.com/smarther/v1.0/chronothermostat/thermoregulation/addressLocation/plants/$plantid/modules/parameter/id/value/$moduleid" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $key" -H "Authorization: $ocm" > /home/pi/scripts/smarther/get_status.tmp
          less /home/pi/scripts/smarther/get_status.tmp | jq '.' | more > /home/pi/scripts/smarther/get_status.json
		  log "Informazioni Recuperate. Controllare il file get_status.json."
		  
		  statusTermostat=`jq -r '.chronothermostats[0].mode' < /home/pi/scripts/smarther/get_status.json`
		  echo {\"statusTermostat\":\"$statusTermostat\"} > /home/homeassistant/.homeassistant/json/smarther/get_status.json

          ;;
     set_programma_1)
	      log "Procedura richiamata con parametro $1"
	      curl -v -X POST "https://api.developer.legrand.com/smarther/v1.0/chronothermostat/thermoregulation/addressLocation/plants/$plantid/modules/parameter/id/value/$moduleid" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $key" -H "Authorization: $ocm" --data-ascii "{\"function\": \"heating\",\"mode\": \"automatic\",\"programs\": [ { \"number\": 1 } ]}"
		  log "Programma 1 impostato sul termostato."
		  sleep 5
		  log "Aggiornamento Stato...."
		  curl --silent -X GET "https://api.developer.legrand.com/smarther/v1.0/chronothermostat/thermoregulation/addressLocation/plants/$plantid/modules/parameter/id/value/$moduleid" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $key" -H "Authorization: $ocm" > /home/pi/scripts/smarther/get_status.tmp
          less /home/pi/scripts/smarther/get_status.tmp | jq '.' | more > /home/pi/scripts/smarther/get_status.json
		  log "Informazioni Recuperate. Controllare il file get_status.json."
		  
		  statusTermostat=`jq -r '.chronothermostats[0].mode' < /home/pi/scripts/smarther/get_status.json`
		  echo {\"statusTermostat\":\"$statusTermostat\"} > /home/homeassistant/.homeassistant/json/smarther/get_status.json

          ;; 
     *)
          log "Parametro non consentito"
          ;;
esac

log "Fine"



(Fabio Possieri) #14

Hi Francesco, sorry to revamp the thread after months.

I saw your script and instructions, nice work!
I managed to successfully test Legrand API from their developer website.

As I’m quite a newby with openHab, I was wondering if you can tell us “how” you have integrated it with openHab2 instance.

Thanks,