libetrv
libetrv copied to clipboard
Add from hassio
Hello Adam I also have danfoss eco bluetoothe and I miss integration with hassio? I see that the works are at an advanced level, will this integration be possible on your part?
Hi djmalin, using Adam lib you can catch data and send to mqtt server. Here is an example, working on this lib.
Sending data to home assistant sensors, you can easly manage them. I'd like to add (for each eco):
- manual / schedule switch
- target temperature slider (in manual mode)
- valve open / close status (data structure not decoded yet, we are talking about in another issue)
- valve slider control (0-100%)
Hope this should be helpful! Andrea
#!/usr/bin/env python import sys from libetrv.device import eTRVDevice, eTRVDeviceMeta from libetrv.cli import CLI, Device import paho.mqtt.publish as publish import paho.mqtt.client as mqtt import time as mytime
from datetime import datetime
MQTT_SERVER = "localhost" MQTT_PORT = "1883"
#DEVICES LIST cucina_id = '00:04:2f:f4:79:a7' cucina_key = 'a556df6ee2d680fb773dcdbc54b26160'
sala_id = '00:04:2f:f4:82:9e' sala_key = '9defd76b905920f577a476f64ed3296e'
camera_id = '00:04:2f:f4:79:97' camera_key = '9556dffe8206dcf8773dcdecf48c1cab'
scale_id = '00:04:2f:f4:79:96' scale_key = '9556dffb809778b3773dcded9e3ac89b'
atrio_id = '00:04:2f:f4:96:d6' atrio_key = 'd5ffff7b0009f5c777a062ae1e8ec26d'
bagno_id = '00:04:2f:f4:82:63' bagno_key = 'e5efd7ea6a9b071d77a476017cd9ba45'
MQTT_PATH_5 = "danfoss/media"
def read_device(address,key): dev = CLI(None,key) d = dev.device(address) n = d.get_name() b = d.get_battery() print(b) t = d.get_temperature() _t = t.split("|") print(_t[0]) print(_t[1]) MQTT_PATH = "danfoss/"+n+"/name" MQTT_PATH_2 = "danfoss/"+n+"/battery" MQTT_PATH_3 = "danfoss/"+n+"/temp_room" MQTT_PATH_4 = "danfoss/"+n+"/temp_target" publish.single(MQTT_PATH, n, hostname=MQTT_SERVER,retain=True) mytime.sleep(2) publish.single(MQTT_PATH_2, b, hostname=MQTT_SERVER,retain=True) mytime.sleep(2) publish.single(MQTT_PATH_3, _t[0], hostname=MQTT_SERVER,retain=True) mytime.sleep(2) publish.single(MQTT_PATH_4, _t[1], hostname=MQTT_SERVER,retain=True) return _t[0]
cucina_t = read_device(cucina_id, cucina_key) sala_t = read_device(sala_id, sala_key) camera_t = read_device(camera_id, camera_key) scale_t = read_device(scale_id, scale_key) atrio_t = read_device(atrio_id, atrio_key) bagno_t = read_device(bagno_id, bagno_key)
try: media = (float(cucina_t)+float(sala_t)+float(camera_t)+float(scale_t)+float(atrio_t)+float(bagno_t))/6 print(str(media)) media = round(media, 2) publish.single(MQTT_PATH_5, media, hostname=MQTT_SERVER,retain=True) except: print("Errore Media")
Hello lollozzo
if you could write step by step where you provided files and configurations, and what did you do to make your method work, I would be very grateful, I am a beginner hassio user, and I'm just learning everything :)
Hi djmalin, did you found data using Adam's lib? Do you need home assistant configuration only?
In Home Assistant you have to set mqqt sensor for each value you want to collect. Here is an exampe, written in sensor.yaml file:
- platform: mqtt
name: "Bagno Battery"
state_topic: "danfoss/Bagno/battery"
unit_of_measurement: '%'
- platform: mqtt
name: "Bagno Temp Room"
state_topic: "danfoss/Bagno/temp_room"
unit_of_measurement: '°C'
- platform: mqtt
name: "Bagno Temp Targ"
state_topic: "danfoss/Bagno/temp_target"
unit_of_measurement: '°C'
You push data to MQTT using python script (my first reply), then you catch in home assistant using sensors. Lovelance configuration is quite easy, just add entities box from gui editor. Here is an example of a horizontal stack with 2 boxes:
cards:
- entities:
- entity: sensor.sala_temp_room
icon: 'mdi:thermometer'
name: Room
type: sensor
unit: °C
- entity: sensor.sala_temp_targ
icon: 'mdi:gauge-full'
name: Target
type: sensor
unit: °C
- entity: sensor.sala_battery
icon: 'mdi:battery'
name: Battery
type: sensor
unit: '%'
show_header_toggle: false
title: Sala
type: entities
- entities:
- entity: sensor.cucina_temp_room
icon: 'mdi:thermometer'
name: Room
type: sensor
unit: °C
- entity: sensor.cucina_temp_targ
icon: 'mdi:gauge-full'
name: Target
type: sensor
unit: °C
- entity: sensor.cucina_battery
icon: 'mdi:battery'
name: Battery
type: sensor
unit: '%'
show_header_toggle: false
title: Cucina
type: entities
font_size: 6
title: Disk
type: horizontal-stack
Hope this should be helpful! Andrea
Hi lollozzo I have such an error Your script (Error loading script danffos.py: Line 36: IndentationError: expected an indented block at statement: 'dev = CLI(None,key) , the libetrv directory has been added to
- conf \ custom_components \ libetrv.
and your script to:
- conf \ python_scripts \ dynffos.py and where do you get these keys from (bagno_key itd..)? thank you very much for your help, she is very helpful to me:)
Hi there, you should fix import path reading this guide:
https://realpython.com/absolute-vs-relative-python-imports/
from ..custom_components.libetrv.cli import CLI, Device
should work, not sure, try it!
-- and where do you get these keys from (bagno_key itd..)? Use Adam's Lib CLI to scan and retrieve key of your devices. python3 -m libetrv.cli - device 00:04:2f:f4:82:9e retrieve-key ** press device button when you run it
Greetings and Merry Christmas :) Andrea
@lollozzo Hello, I am pretty new in python, so could you post your mqtt python script with correct indentation, please? Thank you.
hi guys,
im also interested in this project, i have two valves installed and want to controll them from hassio.
I followed lollozzos guide but the only thing i was able to do was to retrieve the key to one of my valves. Now im trying to make this work with hassio but i also have some errors with the script lollozzo posted here. I
m also new to python and could use more detailed step by step guide how to get this working
thanks
@lollozzo Hello, I am pretty new in python, so could you post your mqtt python script with correct indentation, please? Thank you.
Hi, happy new year! To fix indentation, just indent (1 tab) from: dev = CLI(None,key) to return _t[0]
and fix this block (using ---- to show you):
try: ----media = (float(cucina_t)+float(sala_t)+float(camera_t)+float(scale_t)+float(atrio_t)+float(bagno_t))/6 ----print(str(media)) ----media = round(media, 2) ----publish.single(MQTT_PATH_5, media, hostname=MQTT_SERVER,retain=True) except: ----print("Errore Media")
Greetings! Andrea
hi guys,
im also interested in this project, i have two valves installed and want to controll them from hassio. I followed lollozzo
s guide but the only thing i was able to do was to retrieve the key to one of my valves. Now im trying to make this work with hassio but i also have some errors with the script lollozzo posted here. I
m also new to python and could use more detailed step by step guide how to get this workingthanks
Hi, happy new year! Please show us errors, maybe we can help you. If you retrieved key, now you can communicate with valve in python.
Let us know! Greetings
Hi and Happy new year to all!
Just a couple more question about your setup. Do you run Hass.io in docker? I have the library libetrv folder in custom_components and the script is in python_scripts. I modified the script so i only have one valve and changed the name and also put the mac address and the key i retrieved from the valve. When i run the script i get following error: Warning loading script danfoss.py: Line None: Prints, but never reads 'printed' variable. Error executing script: import not found Do you leave the virtual enviroment run in the background ? What if you restart your PI? Do you have to start it manually? Does the hassio docker have access to the virtual enviroment?
thanks in advance
Hello @lollozzo i have one more problem i can't install bluepy==1.3.0 and xxtea == 1.3.0, i have this error altogether and i can't deal with it, other addons have installed, this is my log: https://imgur.com/a/T43jSSD
Hello again, thank you @lollozzo for your help with correct indentation. Now I have another error... What did I do wrong this time?
Thanks again.
(libetrv) pi@tvpi:~/libetrv $ python3 etrv.py
Traceback (most recent call last):
File "etrv.py", line 43, in <module>
moja_izba_t = read_device(moja_izba_id, moja_izba_key)
File "etrv.py", line 23, in read_device
n = d.get_name()
AttributeError: 'Device' object has no attribute 'get_name'
Just a couple more question about your setup. Do you run Hass.io in docker? -- no, regular installation with apt
I have the library libetrv folder in custom_components and the script is in python_scripts. -- i have standalone home assistant intallation, libetrv in a venv and i run libetrv script to read data by cron.
I modified the script so i only have one valve and changed the name and also put the mac address and the key i retrieved from the valve. When i run the script i get following error: Warning loading script danfoss.py: Line None: Prints, but never reads 'printed' variable. Error executing script: import not found -- yes i guess import path is not correct.
Do you leave the virtual enviroment run in the background ? -- yes, a venv for libetrv, i just run cron with venv on
What if you restart your PI? Do you have to start it manually? -- nope, using cron to run the script, restart is automatic
Does the hassio docker have access to the virtual enviroment? -- nope they share data on mqtt, libetrv script / lib and hassio are standalone
Hello @lollozzo i have one more problem i can't install bluepy==1.3.0 and xxtea == 1.3.0, i have this error altogether and i can't deal with it, other addons have installed, this is my log: https://imgur.com/a/T43jSSD
try pip3, idk sorry
Hello again, thank you @lollozzo for your help with correct indentation. Now I have another error... What did I do wrong this time?
Thanks again.
(libetrv) pi@tvpi:~/libetrv $ python3 etrv.py Traceback (most recent call last): File "etrv.py", line 43, in <module> moja_izba_t = read_device(moja_izba_id, moja_izba_key) File "etrv.py", line 23, in read_device n = d.get_name() AttributeError: 'Device' object has no attribute 'get_name'
mmmh maybe import path is wrong. I use:
- venv (generic folder) --- libetrv_folder (specific venv folder) ------- libetrv ------- bin ------- etc etc ------- myscript.py
With this folder structure, this import should work: from libetrv.device import eTRVDevice, eTRVDeviceMeta from libetrv.cli import CLI, Device
Check import, i guess!
Hi all,
maybe im not that good with this python stuff but i cant get this working.
lets make things clear:
- the libetrv library runs in virtual enviroment (done)
- when you call the script it should connect to the ECO2 valve and read data from it ( how do i know its comunicating with the valve? cant see anything going on )
- then the paho mqtt grabs the data and sends via mqtt to hassio ( i have mosquitto running in hassio how to make paho mqtt comunicate with mosquitto? )
i know its a lot to cover but a more step by step guide would be more appreciated for us less advanced users.
im trying for days to get this to work and dont mind to learn new things but its getting frustrating.
thanks to all
Following, as I have a similar setup and I am considering to implement with Hass.
Thanks a ton for your help improving the Eco2 with this fun project!
lør. 4. jan. 2020 14.07 skrev lasica58 [email protected]:
Hi all,
maybe im not that good with this python stuff but i cant get this working.
lets make things clear:
- the libetrv library runs in virtual enviroment (done)
- when you call the script it should connect to the ECO2 valve and read data from it ( how do i know its comunicating with the valve? cant see anything going on )
- then the paho mqtt grabs the data and sends via mqtt to hassio ( i have mosquitto running in hassio how to make paho mqtt comunicate with mosquitto? )
i know its a lot to cover but a more step by step guide would be more appreciated for us less advanced users.
im trying for days to get this to work and dont mind to learn new things but its getting frustrating.
thanks to all
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AdamStrojek/libetrv/issues/15?email_source=notifications&email_token=AJWJJN7JZ4VCBOKCKELRQKLQ4CCYXA5CNFSM4J37A7N2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEICXVAY#issuecomment-570784387, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJWJJN2X4HWY25KXXFJ2ZW3Q4CCYXANCNFSM4J37A7NQ .
when trying to read the temperature i get:
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/pi/venv/libetrv/libetrv/cli.py", line 79, in
any help?
Hello again @lollozzo
so my folder structure should be the same as yours:
and here is your customized python script:
and I have the same error:
(libetrv) pi@tvpi:~/libetrv $ python3 etrv.py
Traceback (most recent call last):
File "etrv.py", line 43, in <module>
moja_izba_t = read_device(moja_izba_id, moja_izba_key)
File "etrv.py", line 23, in read_device
n = d.get_name()
AttributeError: 'Device' object has no attribute 'get_name'
Oh! i just realize I have password protected mqtt server. Could it be it?
Thank you for your time!
Maybe n = d.get_name() is just n = d.name() ?
Buying new Danfoss ECO 2 tomorrow :-) Best regards
(libetrv) pi@tvpi:~/libetrv $ python3 etrv.py Traceback (most recent call last): File "etrv.py", line 43, in
moja_izba_t = read_device(moja_izba_id, moja_izba_key) File "etrv.py", line 23, in read_device n = d.get_name() AttributeError: 'Device' object has no attribute 'get_name' Oh! i just realize I have password protected mqtt server. Could it be it? Thank you for your time!
sorry i forgot a detail. in cli.py - line 91 i add a couple of methods to catch data in a direct way:
def get_battery(self):
return self._device.battery
def get_name(self):
return self._device.name
def get_temperature(self):
temp = self._device.temperature
return str(temp.room_temperature) + "|" + str(temp.set_point_temperature)
check my version of cli.py, is up to date on github now and i did pull request to Adam
TypeError: a bytes-like object is required, not 'NoneType'
any help?
nontype error is about secred key, check if you pass it correctly, i got that error - at beginning - and it was a bug sending key to class o method
- the libetrv library runs in virtual enviroment (done)
- when you call the script it should connect to the ECO2 valve and read data from it ( how do i know its comunicating with the valve? cant see anything going on )
- Red circle on valve should be turn on when reading data
- then the paho mqtt grabs the data and sends via mqtt to hassio ( i have mosquitto running in hassio how to make paho mqtt comunicate with mosquitto? )
- Check my script, I manage mqtt connection and publish :)
Greetings!
check my version of cli.py, is up to date on github now and i did pull request to Adam
Got it! :-) I can read battery, temp and set temp. Any idea how to add MQTT username and password to your script?
Thank you.
Hi Misosec
I had same issue, edit publish.single lines. add this: auth={'username': 'ik', 'password': 'ik'} example: publish.single("NombreEquipo", data, hostname="127.0.0.1", auth={'username': 'ik', 'password': 'ik'})
best regards
Hi Misosec
I had same issue, edit publish.single lines. add this: auth={'username': 'ik', 'password': 'ik'} example: publish.single("NombreEquipo", data, hostname="127.0.0.1", auth={'username': 'ik', 'password': 'ik'})
best regards
Great! Thank you!
Got 4 Danfoss ECO2's today, code edited with keys, renamed eTRV to room name, and now finally up and running :- Home assistant now shows ECO info. Will there be a guide howto control etrv from home assistant ?
ESPhome has beautiful integration with home assistant. Would be nice to create esphome custom component like one is created for xiaomi ble devices. For xiaomi sensors I am running ESP32 (has wifi and bluetooth) with esphome component built in which works as a bridge for HASS mqtt and ble devices.
Although my main focus is to control ECOs dependant on occupancy, air quality and other factors.
Hi,
Thanks to all. Lollozzo youre the man! i finaly got it working and also can read the data in Hassio.