enesbcs / shellyteacher4domo

Shelly device teacher for Domoticz MQTT Autodiscovery hardware
Apache License 2.0
10 stars 4 forks source link

Request to implement support for ShellyWallDisplay #50

Closed AchilleTalon-Lefuneste closed 8 months ago

AchilleTalon-Lefuneste commented 8 months ago

Great project. However I'm not yet comfortable with adding my own templates.

I just installed a ShellyWallDisplay, with a fully functional MQTT setup. I can see it in MQTT explorer but can't get it to join all the other Shellly devices that I succesfully included in my domoticz thanks to this teacher.

I would love to be able to update the templates so that at least the relay can be controlled through domoticz.

enesbcs commented 8 months ago

I cant find any API spec to the device "ShellyWallDisplay". https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Mqtt/

Without information this wont work. Could you push the manufacturer to publish some data, or can you do some MQTT sniffing on your network when controlling the relay?

AchilleTalon-Lefuneste commented 8 months ago

Sample of MQTT sniffing (using MQTT explorer):

Topic : ShellyWallDisplay-MACADDRESS

online = true

subtopic status:

ble = {} cloud = {"connected": true"} mqtt = {"connected": true} temperature:0 = {"id":0, "tC":23.7, "tF": 74.7} humidity:0 = {"id":0, "rh":39.3} illuminance:0 = {"id":0, "lux":60, "illumination": "twilight"} switch:0 = {"id":0, "output":false, "source":"RPC toggle"} input:0 = {"id":0, "state":false} sys = {"id":"ShellyWallDisplay-MACADDRESS","mac":"MACADDRESS","model":"SAWD-0A1XX10EU1","gen":2,"fw_id":"20240115-105444\/1.2.8-59063a9a","ver":"1.2.8","app":"WallDisplay","auth_en":false,"uptime":63147,"app_uptime":610,"discoverable":false,"cfg_rev":23,"schedule_rev":0,"webhook_rev":0,"platform":"vXD10000M2","available_updates":{},"restart_required":false,"unixtime":1709456460,"relay_in_thermostat":false,"sensor_in_thermostat":false} wifi = {"sta_ip":"xxx.xxx.xxx.xxx","status":"got ip","mac":"MACADDRESS","ssid":"SSID","rssi":-59,"netmask":"xxx.xxx.xxx.xxx","gw":"gatewayaddress","nameserver":"gatewayserver"}

subtopic events:

rpc = {"src":"ShellyWallDisplay-MACADDRESS","dst":"ShellyWallDisplay-MACADDRESS\/events","method":"NotifyStatus","params":{"ts":1709456580,"illuminance:0":{"id":0,"lux":60,"illumination":"twilight"}}}

Switching on or off triggers messages under status and events

status : switch:0 = {"id":0,"output":false,"source":"RPC Toggle"}

events : rpc = {"src":"ShellyWallDisplay-MACADDRESS","dst":"ShellyWallDisplay-MACADDRESS\/events","method":"NotifyStatus","params":{"ts":1709455884,"switch:0":{"id":0,"output":false,"source":"RPC Toggle"}}}

enesbcs commented 8 months ago

Thank you for debugging, based on your finding i think this has to be a working template for it:

[shellywalldisplay] # Shelly Wall Display
topic=%discovery_prefix%/sensor/%shelly_id%/RSSI/config
payload={"device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"},"dev_cla": "signal_strength","enabled_by_default":true,"entity_category":"diagnostic","~": "%shelly_topic%/","json_attributes_topic":"~status/wifi","name": "%shelly_id% WiFi Signal","state_class":"measurement","state_topic":"~status/wifi","unique_id":"%shelly_id%-rssi","unit_of_measurement":"dBm","value_template":"{{ value_json.rssi }}","icon": "mdi:signal"}
topic=%discovery_prefix%/sensor/%shelly_id%/temperature/config
payload={"device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"},"name":"%shelly_id% Temperature","device_class":"temperature","enabled_by_default":true,"~": "%shelly_topic%/","json_attributes_topic":"~status/temperature:0","state_class":"measurement","state_topic":"~status/temperature:0","unique_id":"%shelly_id%-temperature","unit_of_measurement":"C","value_template":"{{ value_json.tC }}"}
topic=%discovery_prefix%/sensor/%shelly_id%/humidity/config
payload={"device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"},"name":"%shelly_id% Humidity","device_class":"humidity","enabled_by_default":true,"~": "%shelly_topic%/","json_attributes_topic":"~status/humidity:0","state_class":"measurement","state_topic":"~status/humidity:0","unique_id":"%shelly_id%-humidity","unit_of_measurement":"%","value_template":"{{ value_json.rh }}"}
topic=%discovery_prefix%/sensor/%shelly_id%/lux/config
payload={"name":"%shelly_id% Illuminance","device_class":"illuminance","stat_cla": "measurement","enabled_by_default":true,"~": "%shelly_topic%/","json_attributes_topic":"~status/illuminance:0","state_class":"measurement","state_topic":"~status/illuminance:0","unique_id":"%shelly_id%-illuminance","unit_of_measurement":"lx","value_template":"{{ value_json.lux }}"}
topic=%discovery_prefix%/switch/%shelly_id%/config
payload={"name": "%shelly_topic% Relay 0", "cmd_t": "~rpc", "pl_off": "{\"id\":1,\"src\":\"%shelly_id%\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}", "pl_on": "{\"id\":1,\"src\":\"%shelly_id%\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}", "stat_t": "~status/switch:0", "val_tpl": "{{ value_json.output }}","stat_off": "false","stat_on": "true","avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "uniq_id": "%shelly_id%-0", "qos": 0, "device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"}, "~": "%shelly_topic%/"}
topic=%discovery_prefix%/binary_sensor/%shelly_id%/input/config
payload={"name": "%shelly_topic% Input 0", "val_tpl": "{{ value_json.state }}","stat_off": "false","stat_on": "true","enabled_by_default": true, "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "uniq_id": "%shelly_id%-0-input", "qos": 0, "device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"}, "~": "%shelly_topic%/", "stat_t": "~status/input:0"}
topic=%discovery_prefix%/binary_sensor/%shelly_id%-online/config
payload={"name": "%shelly_id% Online", "stat_t": "~online", "uniq_id": "%shelly_id%-online", "~": "%shelly_topic%/", "pl_on": "true", "pl_off": "false"}

If you can add it to the end of your mqtt_templates_gen2.txt file you can try to teach it.

AchilleTalon-Lefuneste commented 8 months ago

Almost perfect. You got it right except for the uppercase in the device type: if I change "shellywalldisplay" to "ShellyWallDisplay" in your proposed template, it works like a charm.

Great job, and thank you for your fast answer.

Just for the record (didn't do much of the work), here is the correct template:

[ShellyWallDisplay] # Shelly Wall Display
topic=%discovery_prefix%/sensor/%shelly_id%/RSSI/config
payload={"device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"},"dev_cla": "signal_strength","enabled_by_default":true,"entity_category":"diagnostic","~": "%shelly_topic%/","json_attributes_topic":"~status/wifi","name": "%shelly_id% WiFi Signal","state_class":"measurement","state_topic":"~status/wifi","unique_id":"%shelly_id%-rssi","unit_of_measurement":"dBm","value_template":"{{ value_json.rssi }}","icon": "mdi:signal"}
topic=%discovery_prefix%/sensor/%shelly_id%/temperature/config
payload={"device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"},"name":"%shelly_id% Temperature","device_class":"temperature","enabled_by_default":true,"~": "%shelly_topic%/","json_attributes_topic":"~status/temperature:0","state_class":"measurement","state_topic":"~status/temperature:0","unique_id":"%shelly_id%-temperature","unit_of_measurement":"C","value_template":"{{ value_json.tC }}"}
topic=%discovery_prefix%/sensor/%shelly_id%/humidity/config
payload={"device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"},"name":"%shelly_id% Humidity","device_class":"humidity","enabled_by_default":true,"~": "%shelly_topic%/","json_attributes_topic":"~status/humidity:0","state_class":"measurement","state_topic":"~status/humidity:0","unique_id":"%shelly_id%-humidity","unit_of_measurement":"%","value_template":"{{ value_json.rh }}"}
topic=%discovery_prefix%/sensor/%shelly_id%/lux/config
payload={"name":"%shelly_id% Illuminance","device_class":"illuminance","stat_cla": "measurement","enabled_by_default":true,"~": "%shelly_topic%/","json_attributes_topic":"~status/illuminance:0","state_class":"measurement","state_topic":"~status/illuminance:0","unique_id":"%shelly_id%-illuminance","unit_of_measurement":"lx","value_template":"{{ value_json.lux }}"}
topic=%discovery_prefix%/switch/%shelly_id%/config
payload={"name": "%shelly_topic% Relay 0", "cmd_t": "~rpc", "pl_off": "{\"id\":1,\"src\":\"%shelly_id%\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}", "pl_on": "{\"id\":1,\"src\":\"%shelly_id%\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":true}}", "stat_t": "~status/switch:0", "val_tpl": "{{ value_json.output }}","stat_off": "false","stat_on": "true","avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "uniq_id": "%shelly_id%-0", "qos": 0, "device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"}, "~": "%shelly_topic%/"}
topic=%discovery_prefix%/binary_sensor/%shelly_id%/input/config
payload={"name": "%shelly_topic% Input 0", "val_tpl": "{{ value_json.state }}","stat_off": "false","stat_on": "true","enabled_by_default": true, "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "uniq_id": "%shelly_id%-0-input", "qos": 0, "device": {"identifiers": ["%shelly_mac%"],"manufacturer": "Shelly","model": "%shelly_model%","name": "%shelly_id%"}, "~": "%shelly_topic%/", "stat_t": "~status/input:0"}
topic=%discovery_prefix%/binary_sensor/%shelly_id%-online/config
payload={"name": "%shelly_id% Online", "stat_t": "~online", "uniq_id": "%shelly_id%-online", "~": "%shelly_topic%/", "pl_on": "true", "pl_off": "false"}