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

0 Likes

BTicino Smarther thermostat binding
(Rich Koshak) #2

Search is pretty helpful.

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

0 Likes

(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?

0 Likes

(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.

0 Likes

(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!

0 Likes

(Rich Koshak) #6

You will have to purchase an IP gateway.

0 Likes

(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

0 Likes

(twiggo) #8

hi massi, really really thanks…

0 Likes

(Arnaud) #9

Hello,
New website for developpers.

0 Likes

(twiggo) #10

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

0 Likes

(Francesco Ranieri) #11

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

0 Likes

(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

0 Likes

(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"


2 Likes

(Fabio) #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,

0 Likes

(Luca) #15

Francesco, can you elaborate a little bit more how you did the integration in Home Assistant?. I’ve already signed in with Legrand and I think I have all necessary info to go ahead but my programming skills are not such that I can do it alone! can you help?

thanks

Luca

0 Likes

(mix) #16

Francesco, if I did not misunderstood, you succeded adding your Smarther in OpenHab 2… is this correct ? Could you please explain this a little bit more ? Thank you.

0 Likes

(Fabio) #17

Hi there!
Starting from Francesco’s work I’ve succesfully integrated my home Smarther Chronothermostat with openHAB v2.4, via Legrand’s API v2 (with status notifications).
You can find it here: https://github.com/MrRonfo/openhab-smarther
Rough work based on bash and php scripting, but it works :slight_smile:
Cheers,

1 Like

(Andrea ) #18

Hi @Mr_Ronfo,
thank you for your contribution.
I’m a total noob. I tried to use your script to integrate my Thermostat but I failed.
I’ll write down what is not clear to me, asking for your help:

  1. First Reply Url = I entered http://192.168.xxx.yyy:8080/smarther/smarther-auth.php
    The URL is what I type in chromium to access OpenHab (http://192.168.xxx.yyy:8080). Should I have entered the public IP address given by my provider instead of that one? I have NGinx with php service installed.

  2. Copy the smarther-api.sh script into smarther/ directory and give it execute grant, then change the owner of smarther/ branch:

chmod +x /etc/openhab2/scripts/smarther/smarther-api.sh
sudo chown -R openhab:openhabian /etc/openhab2/scripts/smarther/

I don’t have Hassbian, I installed OpenHab over Raspbian. In my case it should be

chmod +x /etc/openhab2/scripts/smarther/smarther-api.sh
sudo chown -R openhab:openhab /etc/openhab2/scripts/smarther/

Am I right?

  1. Script configuration
    here you can read part of my smarther-api.sh script
/bin/bash
#-------------------------------------------------------------------------------
# BEGIN -- Configuration Section
#--------------------------------
# API subscription key
subscription_key="xxxxxxxxx"
# Application credentials
client_id="yyyyyyyyyyyyyyyyyyyyy"
client_secret="xxxxB"yyyyyy"
redirect_uri="http://192.168.1.122:8080/smarther/smarther-auth.php"
# Chronothermostat topology
plant_id="zzzzzzz"
module_id="ffffffffffffffffffffffff"
# Cloud2Cloud notification callback URL
notify_url="http://192.168.1.122:8080/smarther/smarther-c2c.php
# Log level
log_level="INFO"

Is my subscription key inserted correctly? (should I keep the quotation marks before and after “yoursubscriptionkey”?).
I’m asking this because unfortunately my client secret has a single quotation mark within its code, and I’m afraid the system could interpret it in a wrong way (in facts the code becomes grayafter the q mark, not yellow as it should be).

  1. Finally, when I execute the smarther-api.sh script I get NOTHING, no URL to visit

I hope I explained correctly my problems.
Thank you in advance

0 Likes

(Fabio) #19

Hi @fenderislife, you’re more than welcome,

  1. Yes, it must be the public URL pointing to your smarther-auth.php script - as this resource will later be called back by the OAuth remote server to complete the initial authentication procedure. Thus, better if you first test that your script is actually accessible from the Internet, before registering the new application…

  2. In my setup openhabian is the current user I copy the script to the server with, so it is created under that user:group. OH2 instead runs as openhab user, thus I had to change the script user to openab to avoid access errors when the script called from within OH2 tries to update its own json service file. The important thing here is to make sure the script is owned by the same user your OH2 instance runs as. Your feedback on how you’ll solve in your case would be appreciated, and useful to expand my setup instructions :slight_smile:

  3. Keep the quotation marks before and after your key, and escape the quotation mark IN your key using backslash ( \" ). In your example above, this would become:

client_secret="xxxxB\"yyyyyy"

Please note that both the redirect_uri and the notify_url must be public URL. The 1st one I’ve explained it in #1, the 2nd one will later be called by Azure remote cloud to push thermostat status notifications to your OH2 server.

  1. This should be due to wrong configuration of redirect_uri in your smarther-api.sh script. As explained in #3, it must be a public UR and, more, it must be set with the same value as the First Reply URL you specify when registering the application on Legrand’s website.

Hope this helps :wink:

Should you have further questions, please open an issue on my GitHub project.

Cheers

1 Like

(Andrea ) #20

This edit is just to write down that thanks to @Mr_Ronfo’s support I managed to make openhab_smarther fully work.

Thank you again Fabio.

0 Likes