mrwiwi / tydom2mqtt

Link between a Delta Dore's Tydom Hub and and a MQTT broker, unofficial of course.
MIT License
28 stars 17 forks source link

Add support for Tywatt #42

Closed nels83 closed 2 years ago

nels83 commented 2 years ago

Is it possible to add support for Tywatt ?

I use it with tydom-client and mqtt by hand for now and it works really well (integrated in the new Energy panel!). Only problem is that it needs polling so I don't know if it would be easy for you.

Here is an example of how I use it (no error handling, really quick an dirty and first HA dev so there may be mistakes) :

Discover : mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/sensor/tydom_power_total/config" -m '{"unique_id": "tydom_power_total", "name": "Total consumption", "unit_of_measurement": "Wh", "device_class": "energy", "state_class": "total_increasing", "state_topic": "homeassistant/sensor/tydom_power_total/state"}'

Get data : request /devices/XXXX/endpoints/XXXX/cdata?name=energyIndex&dest=ELEC_TOTAL&reset=false --username USER --password PASS --hostname IP --command

Update : mosquitto_pub -r -h 127.0.0.1 -p 1883 -t "homeassistant/sensor/tydom_power_total/state" -m VALUE

You can replace ELEC_TOTAL with ELEC_HEATING, ELEC_COOLING, ELEC_HOTWATER, ELEC_OUTLET, ELEC_OTHER (you can get the list using request /devices/cmeta)

I don't think energyHisto and energyDistrib commands would be of any use, however energyInstant is interesting (using "unit_of_measurement": "VA", "device_class": "current", "state_class": "measurement").

Thanks for the great software !

RomainGx commented 2 years ago

Hi @nels83 I am interested by the information you get about energy. I have a Tywatt 2000 and I see its cmeta information when requesting /devices/cmeta (energyHisto, energyDistrib, energyInstant and energyIndex, like you).

However when requesting /devices/XXXX/endpoints/XXXX/cdata?name=energyIndex&dest=ELEC_TOTAL&reset=false using my Python script I got nothing

Could you please send me your script, so I test it to see if I can get data?

DEBUG:websockets.protocol:client - state = OPEN
DEBUG:websockets.protocol:client > Frame(fin=True, opcode=2, data=b'\x02GET /devices/XXXXXX/endpoints/XXXXXX/cdata?name=energyIndex&dest=ELEC_TOTAL&reset=false HTTP/1.1\r\nContent-Length: 0\r\nContent-Type: application/json; charset=UTF-8\r\nTransac-Id: 0\r\n\r\n', rsv1=False, rsv2=False, rsv3=False)
DEBUG:websockets.protocol:client - event = data_received(<150 bytes>)
DEBUG:websockets.protocol:client < Frame(fin=True, opcode=2, data=b'\x02HTTP/1.1 200 OK\r\nServer: Tydom-001A2504232D\r\nUri-Origin: /devices/XXXXXX/endpoints/XXXXXX/cdata\r\nContent-Type: application/json\r\nContent-Length: 0\r\nTransac-Id: 0\r\n\r\n', rsv1=False, rsv2=False, rsv3=False)
b'\x02HTTP/1.1 200 OK\r\nServer: Tydom-001A2504232D\r\nUri-Origin: /devices/XXXXXX/endpoints/XXXXXX/cdata\r\nContent-Type: application/json\r\nContent-Length: 0\r\nTransac-Id: 0\r\n\r\n'
DEBUG:websockets.protocol:client - state = CLOSING
DEBUG:websockets.protocol:client > Frame(fin=True, opcode=8, data=b'\x03\xe8', rsv1=False, rsv2=False, rsv3=False)
DEBUG:websockets.protocol:client - event = data_received(<2 bytes>)
DEBUG:websockets.protocol:client - event = data_received(<2 bytes>)
DEBUG:websockets.protocol:client < Frame(fin=True, opcode=8, data=b'\x03\xe8', rsv1=False, rsv2=False, rsv3=False)
DEBUG:websockets.protocol:client - event = eof_received()
DEBUG:websockets.protocol:client - event = connection_lost(None)
DEBUG:websockets.protocol:client - state = CLOSED
DEBUG:websockets.protocol:client x code = 1000, reason = [no reason]
DEBUG:websockets.protocol:client x closing TCP connection

Thanks

nels83 commented 2 years ago

Sure, here is the exact command I use to get the data : NODE_TLS_REJECT_UNAUTHORIZED=0 timeout 60s npx tydom-client request /devices/XXXXXX/endpoints/XXXXXX/cdata?name=energyIndex\&dest=ELEC_TOTAL\&reset=false --username USER --password PASS --hostname IP --command --file out.json Then I get the value from the returned JSON : cat out.json | jq ".[]|.[]|.counter"

Maybe you do not use --command (I don't how it is handled in your Python script)?

nels83 commented 2 years ago

Please follow discussion at the new repo : https://github.com/fmartinou/tydom2mqtt/issues/20