Closed enesbcs closed 1 year ago
As it is a Gen2 device, it can only be controlled by RPC commands, which may be encapsulated into MQTT as it is currently done in the template sections "pl_open", "pl_cls" and "pl_stop".
The Gen2 set position RPC command is like this: https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Cover#covergotoposition-example
According to HA docs ( https://www.home-assistant.io/integrations/cover.mqtt/ ) it might be something similar:
"set_position_topic": "shellyplus2pm-XXXXXXXXXX/rpc"
"set_position_template": '{"id":0,"src":"shellyplus2pm-XXXXXXXXXX","method":"Cover.GoToPosition","params":{"id":0,"pos":{{ position }}}}'
The only question is, that set_position_template is supported by Domoticz, or not...
Unfortunately I can't get it to work, someone has a solution that works?
Thanks for all the support and the great work!
Additional information:
If I set the roller shutter to 70% in the Shelly app, I actually see the roller shutter at 70% in Domotics on the slider. So Domoticz takes over the information from the Shelly app well. However, when I set the roller shutter to 70% in Domoticz, nothing happens and the communication from Domoticz to Shelly does not seem to work properly.
Hopefully someone has a working and simpel solution?
If anyone wants to try it, this is the best template extension which has to be work... but it do not works:
"set_pos_t": "~rpc", "set_pos_tpl": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.GoToPosition\",\"params\":{\"id\":0,\"pos\": {{ position }} }}"
Domoticz current MQTT AD code supports partially set_pos_tpl, but messes up JSON and " in the output so it has no chance that it will work, until it is fixed on the Domoticz side.
Until that time, only open/close/stop commands can be used on all Gen2 Cover devices.
Hi Alexander,
I'm a bit stubborn to get it work and tested your latest template information and in the following way:
In templates_gen2.txt I replaced the following:
pos_t": "~status/cover:0", "pos_tpl": "{{ value_json.current_pos }}"
Into:
“set_pos_t": "~rpc", "set_pos_tpl": "{"id":0,"src":"domoticz","method":"Cover.GoToPosition","params":{"id":0,"pos":"{{ position }}"}}"
But still not working to set a position in Domoticz
I see in my MQQT explorer that this change causes the config to go wrong. Instead of all separate lines, it becomes one long line.
Could there be a comma, colon or brackets too much or too little in your solution?
Whether or not it works in Domoticz, the config that sends the template to the Shelly must be correct, right??
Thanks again for your replay.
Regards, Huib
Van: Alexander Nagy @.> Beantwoorden - Aan: enesbcs/shellyteacher4domo @.> Datum: maandag 5 juni 2023 om 17:51 Aan: enesbcs/shellyteacher4domo @.> CC: Huib Fenenga @.>, Manual @.***> Onderwerp: Re: [enesbcs/shellyteacher4domo] Shelly 2PM set_position error (Issue #13)
If anyone wants to try it, this is the best template extension which has to be work... but it do not works:
"set_pos_t": "~rpc", "set_pos_tpl": "{"id":0,"src":"domoticz","method":"Cover.GoToPosition","params":{"id":0,"pos":"{{ position }}"}}"
Domoticz current MQTT AD code supports partially set_pos_tpl, but messes up JSON and " in the output so it has no chance that it will work, until it is fixed on the Domoticz side.
— Reply to this email directly, view it on GitHubhttps://github.com/enesbcs/shellyteacher4domo/issues/13#issuecomment-1577054768, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A7WY6I4KY6CN3A4ZUTTU3U3XJX6A7ANCNFSM6AAAAAAYH7EVTQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>
"position topic" and "set position topic" are not the same: https://www.home-assistant.io/integrations/cover.mqtt/#set_position_template
But you are right, the result is not a correct JSON, i have made a semantically correct template, and Domoticz is unable to interpret it.
Opened a ticket on Domoticz github, you can check the details there: https://github.com/domoticz/domoticz/issues/5711
Hopefully someone has a working and simpel solution?
I only has a complex solution.
In today comit i've added a Cover Roller Pos template with SetPositionTopic: https://github.com/enesbcs/shellyteacher4domo/commit/4d6d5e43b35119381a5f7256239f2db4713eff7a
I've tested the above with HomeAssistant and it works as expected, this template generates the following format, when position changed in HA:
{
"id":0,"src":"domoticz","method":"Cover.GoToPosition","params":{"id":0,"pos": 100}
}
But in Domoticz the template support is very basic and resulted format looks like this:
{
"id:0,src:domoticz,method:Cover.GoToPosition,params:id:0,pos: position": 100
}
The Domoticz support will not be 100% in the near future, but another solution may be possible, as Gen2 devices are scriptable. You can add the following script to your Gen2 Cover devices, and make it autostart:
https://github.com/enesbcs/shelly-script-examples/blob/main/shelly2p-domo-coverfix.js
If you are not familiar how the Scripts are working on Shelly, please consult with the manual: https://shelly-api-docs.shelly.cloud/gen2/Scripts/Tutorial/
Any update on this?
waiting some response from anybody who has a 2PM for testing... i havent got.
I have shelly plus 2pm, so if you want me to test things then let me know!
I also own a shelly pro4pm btw.....
Yep, i am interested in the 2pm test results.. included with the MQTT Explorer values in case the fix is not working.
ok, installed MQTT Explorer,
This is the data I get from Shellyplus 2PM:
{
“name”: “Rolluik slaapkamer midden”,
“id”: “shellyplus2pm-XXX”,
“mac”: “XXX”,
“slot”: 0,
“model”: “SNSW-102P16EU”,
“gen”: 2,
“fw_id”: “20230803-125311/1.0.0-gaec0744”,
“ver”: “1.0.0”,
“app”: “Plus2PM”,
“auth_en”: false,
“auth_domain”: null,
“profile”: “cover”
}
Op 15-08-2023 19:36 schreef Alexander Nagy ***@***.***>:
Yep, i am interested in the 2pm test results.. with the MQTT Explorer values in case the fix is not working. —Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
I appreciate your intention, but I can't really understand what you wrote. MQTT has a path and a payload value. You just entered some payload from something. (?)
Let me show you how a complete MQTT debugging should look like: Firstly: my autodiscovery prefix is "homeassistant/"
When my Shelly1 Plus starts up, it sends the following MQTT statement:
path: shellyplus1-a1034aac1520/online
payload: true
When ShellyTeacher discovers the shelly1 plus (catching the above /online message) than it sends this commands to it:
path: shellyplus1-a1034aac1520/rpc
payload: {"id":`` 1, "src":"shellies_discovery", "method":"Shelly.GetConfig"}
The response from device arrives to:
path: shellies_discovery/rpc
payload:
{"id":1,"src":"shellyplus1-a1034aac1520","dst":"shellies_discovery","result":{"ble":{"enable":true,"rpc":{"enable":true}},"cloud":{"enable":false,"server":"iot.shelly.cloud:6012/jrpc"},"input:0":{"id":0, "name":null, "type":"switch","invert":false,"factory_reset":true},"mqtt":{"enable":true,"server":"192.168.1.3","client_id":"shellyplus1-a1034aac1520","user":null,"topic_prefix":"shellyplus1-a1034aac1520","rpc_ntf":true,"status_ntf":true,"use_client_cert":false},"script:1":{"id":1, "name":"script_1", "enable":false},"switch:0":{"id":0, "name":null,"in_mode":"follow","initial_state":"on", "auto_on":false, "auto_on_delay":60.00, "auto_off":false, "auto_off_delay":60.00},"sys":{"device":{"name":null,"mac":"A1034AAC1520","fw_id":"20230209-131418/0.13.0-g68ba560","discoverable":true,"eco_mode":false,"addon_type":null},"location":{"tz":"Europe/Budapest","lat":46.685390,"lon":21.091650},"debug":{"mqtt":{"enable":false},"websocket":{"enable":true},"udp":{"addr":null}},"ui_data":{},"rpc_udp":{"dst_addr":null,"listen_port":null},"sntp":{"server":"time.google.com"},"cfg_rev":10},"wifi":{"ap":{"ssid":"ShellyPlus1-A1034AAC1520","is_open":true, "enable":true, "range_extender": {"enable":false}},"sta":{"ssid":"wolfcave2","is_open":false, "enable":true, "ipv4mode":"dhcp","ip":null,"netmask":null,"gw":null,"nameserver":null},"sta1":{"ssid":null,"is_open":true, "enable":false, "ipv4mode":"dhcp","ip":null,"netmask":null,"gw":null,"nameserver":null},"roam":{"rssi_thr":-80,"interval":60}},"ws":{"enable":false,"server":null,"ssl_ca":"ca.pem"}}}
From this payload the ShellyTeacher detects the device type and writes this text to output log:
>>>GEN2 device shellyplus1-a1034aac1520 shellyplus1-a1034aac1520 found
and sends out the proper "/config" templates under "homeassistant/":
path: homeassistant/switch/shellyplus1-a1034aac1520-0/config
payload:
{"name": "shellyplus1-a1034aac1520 Relay 0", "cmd_t": "~rpc", "pl_off": "{\"id\":1,\"src\":\"shellyplus1-a1034aac1520\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}", "pl_on": "{\"id\":1,\"src\":\"shellyplus1-a1034aac1520\",\"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": "shellyplus1-a1034aac1520-0", "qos": 0, "device": {"identifiers": ["A1034AAC1520"],"manufacturer": "Shelly","model": "shellyplus1","name": "shellyplus1-a1034aac1520"}, "~": "shellyplus1-a1034aac1520/"}
path: homeassistant/binary_sensor/shellyplus1-a1034aac1520-0/input/config
payload:
{"name": "shellyplus1-a1034aac1520 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": "shellyplus1-a1034aac1520-0-input", "qos": 0, "device": {"identifiers": ["A1034AAC1520"],"manufacturer": "Shelly","model": "shellyplus1","name": "shellyplus1-a1034aac1520"}, "~": "shellyplus1-a1034aac1520/", "stat_t": "~status/input:0"}
path: homeassistant/select/shellyplus1-a1034aac1520/input_event-0/config
payload:
{"name": "shellyplus1-a1034aac1520 Input Event 0", "json_attributes_topic": "~events/rpc", "value_template":"{{value_json['params']['events'][0].event}}", "cmd_t": "~dummy", "frc_upd": "false", "enabled_by_default": false, "uniq_id": "shellyplus1-a1034aac1520-event-0", "~":"shellyplus1-a1034aac1520/", "dev_cla": "event", "stat_cla": "selector" , "ops":["-","btn_down","btn_up","single_push","double_push","triple_push","long_push"] }
path: homeassistant/sensor/shellyplus1-a1034aac1520-0/temperature/config
payload:
{"name": "shellyplus1-a1034aac1520 Temperature", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus1-a1034aac1520-temperature", "qos": 0, "~":"shellyplus1-a1034aac1520/", "entity_category": "diagnostic", "dev_cla": "temperature", "stat_cla": "measurement", "unit_of_meas": "°C","stat_t": "~status/switch:0", "val_tpl": "{{ value_json['temperature'].tC }}", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false"}
From the above temperature template its clearly seen that i have to await data to a path that contains "status/switch:0".
At this point, the Domoticz AD MQTT hardware sees the new /config templates and creates the three Switch devices Relay, Input and InputEvent. But Temperature is not yet created, until the first data arrives from Shelly 1 Plus. (and every non-switch devices = sensors works like this example temperature sensor)
2023-08-16 18:08:55.251 [7fcfa77fe640] Status: mqttad: discovered: shellyplus1-a1034aac1520/shellyplus1-a1034aac1520 Relay 0 (unique_id: shellyplus1-a1034aac1520-0)
2023-08-16 18:08:55.466 [7fcfa77fe640] Status: mqttad: discovered: shellyplus1-a1034aac1520/shellyplus1-a1034aac1520 Input 0 (unique_id: shellyplus1-a1034aac1520-0-input)
2023-08-16 18:08:55.686 [7fcfa77fe640] Status: mqttad: discovered: shellyplus1-a1034aac1520-event-0/shellyplus1-a1034aac1520 Input Event 0 (unique_id: shellyplus1-a1034aac1520-event-0)
2023-08-16 18:08:55.570 [7fcfa77fe640] Status: mqttad: discovered: shellyplus1-a1034aac1520-temperature/shellyplus1-a1034aac1520 Temperature (unique_id: shellyplus1-a1034aac1520-temperature)
After some time a status will arrive from Shelly 1 Plus, but i am a little impatient so i pressed the Relay to switch its status to OFF and then ON. And magically the data suddenly arrived:
path: shellyplus1-a1034aac1520/status/switch:0
payload:
{"id":0, "source":"MQTT", "output":false,"temperature":{"tC":55.6, "tF":132.1}}
Then Domoticz creates the temperature sensor device and it has data as 55.6C.
If you are able to debug the Shelly2Pm in such depth, then i can tell what can be the problem. And please use Code tag (<> on the editor toolbar) when posting JSON data.
ok, let me try to reproduce that with a ShellyPLUS2PM device in "Cover-mode" I use MQTT Explorer and I use the Python script, not the GUI.
path: shellies/shellyplus2pm-XXX/announce
payload:
{ "name": "Rolluik slaapkamer midden", "id": "shellyplus2pm-XXX", "mac": "XXX", "slot": 0, "model": "SNSW-102P16EU", "gen": 2, "fw_id": "20230803-125311/1.0.0-gaec0744", "ver": "1.0.0", "app": "Plus2PM", "auth_en": false, "auth_domain": null, "profile": "cover" }
path: shellies_discovery/rpc
payload:
{ "id": 1, "src": "shellyplus2pm-XXXX", "dst": "shellies_discovery", "result": { "ble": { "enable": true, "rpc": { "enable": true }, "observer": { "enable": false } }, "cloud": { "enable": false, "server": "iot.shelly.cloud:6012/jrpc" }, "cover:0": { "id": 0, "name": "Rolluik slaapkamer midden", "motor": { "idle_power_thr": 2, "idle_confirm_period": 0.25 }, "maxtime_open": 60, "maxtime_close": 60, "initial_state": "stopped", "invert_directions": false, "in_mode": "dual", "swap_inputs": false, "safety_switch": { "enable": false, "direction": "both", "action": "stop", "allowed_move": null }, "power_limit": 2800, "voltage_limit": 280, "undervoltage_limit": 0, "current_limit": 10, "obstruction_detection": { "enable": false, "direction": "both", "action": "stop", "power_thr": 127, "holdoff": 1 } }, "input:0": { "id": 0, "name": null, "type": "button", "invert": false, "factory_reset": true }, "input:1": { "id": 1, "name": null, "type": "button", "invert": false, "factory_reset": true }, "mqtt": { "enable": true, "server": "192.168.0.146:1883", "client_id": "shellyplus2pm-XXX", "user": "Domoticz", "topic_prefix": "shellyplus2pm-XXX", "rpc_ntf": true, "status_ntf": true, "use_client_cert": false, "enable_rpc": true, "enable_control": true }, "script:1": { "id": 1, "name": "script_1", "enable": false }, "sys": { "device": { "name": "Rolluik slaapkamer midden", "mac": "XXX", "fw_id": "20230803-125311/1.0.0-gaec0744", "discoverable": true, "eco_mode": false, "profile": "cover", "addon_type": null }, "location": { "tz": "Europe/Amsterdam", "lat": XXX, "lon": XXX }, "debug": { "level": 2, "file_level": null, "mqtt": { "enable": false }, "websocket": { "enable": false }, "udp": { "addr": null } }, "ui_data": {}, "rpc_udp": { "dst_addr": null, "listen_port": null }, "sntp": { "server": "time.google.com" }, "cfg_rev": 22 }, "wifi": { "ap": { "ssid": "ShellyPlus2PM-XXX", "is_open": true, "enable": false, "range_extender": { "enable": false } }, "sta": { "ssid": "XXX", "is_open": false, "enable": true, "ipv4mode": "static", "ip": "192.168.0.104", "netmask": "255.255.255.0", "gw": "192.168.0.1", "nameserver": null }, "sta1": { "ssid": null, "is_open": true, "enable": false, "ipv4mode": "dhcp", "ip": null, "netmask": null, "gw": null, "nameserver": null }, "roam": { "rssi_thr": -80, "interval": 60 } }, "ws": { "enable": false, "server": null, "ssl_ca": "ca.pem" } } }
GEN2 device shellyplus2pm-XXX shellyplus2pm-XXX found
path: homeassistant/switch/shellyplus2pm-XXX-0/config
payload
{ "name": "shellyplus2pm-XXX Relay 0", "cmd_t": "~rpc", "pl_off": "{\"id\":1,\"src\":\"shellyplus2pm-XXX\",\"method\":\"Switch.Set\",\"params\":{\"id\":0,\"on\":false}}", "pl_on": "{\"id\":1,\"src\":\"shellyplus2pm-XXX\",\"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": "shellyplus2pm-XXX-0", "qos": 0, "device": { "identifiers": [ "XXX" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX" }, "~": "shellyplus2pm-XXX/" }
path: homeassistant/switch/shellyplus2pm-XXX-1/config
payload
{ "name": "shellyplus2pm-XXX Relay 1", "cmd_t": "~rpc", "pl_off": "{\"id\":2,\"src\":\"shellyplus2pm-XXX\",\"method\":\"Switch.Set\",\"params\":{\"id\":1,\"on\":false}}", "pl_on": "{\"id\":2,\"src\":\"shellyplus2pm-XXX\",\"method\":\"Switch.Set\",\"params\":{\"id\":1,\"on\":true}}", "stat_t": "~status/switch:1", "val_tpl": "{{ value_json.output }}", "stat_off": "false", "stat_on": "true", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "uniq_id": "shellyplus2pm-XXX-1", "qos": 0, "~": "shellyplus2pm-XXX/" }
path: homeassistant/binary_sensor/shellyplus2pm-XXX-0/input/config
payload:
{ "name": "shellyplus2pm-XXX 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": "shellyplus2pm-XXX-0-input", "qos": 0, "device": { "identifiers": [ "XXX" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX" }, "~": "shellyplus2pm-XXX/", "stat_t": "~status/input:0" }
path: homeassistant/binary_sensor/shellyplus2pm-XXX-1/input/config
payload:
{ "name": "shellyplus2pm-XXXInput 1", "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": "shellyplus2pm-XXX-1-input", "qos": 0, "~": "shellyplus2pm-XXX/", "stat_t": "~status/input:1" }
path: homeassistant/sensor/shellyplus2pm-XXX-0/temperature/config
payload:
{ "name": "shellyplus2pm-XXX Temperature 0", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus2pm-XXX -temperature-0", "qos": 0, "~": "shellyplus2pm-XXX /", "entity_category": "diagnostic", "dev_cla": "temperature", "stat_cla": "measurement", "unit_of_meas": "°C", "stat_t": "~status/switch:0", "val_tpl": "{{ value_json['temperature'].tC }}", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false" }
path: homeassistant/sensor/shellyplus2pm-XXX-1/temperature/config
payload:
{ "name": "shellyplus2pm-XXXTemperature 1", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus2pm-XXX-temperature-1", "qos": 0, "~": "shellyplus2pm-XXX/", "entity_category": "diagnostic", "dev_cla": "temperature", "stat_cla": "measurement", "unit_of_meas": "°C", "stat_t": "~status/switch:1", "val_tpl": "{{ value_json['temperature'].tC }}", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false" }
path: homeassistant/sensor/shellyplus2pm-XXX-0/voltage/config
payload:
{ "name": "shellyplus2pm-XXXVoltage 0", "~": "shellyplus2pm-XXX/", "stat_t": "~status/switch:0", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus2pm-XXX-0-voltage", "qos": 0, "dev_cla": "voltage", "stat_cla": "measurement", "unit_of_meas": "V", "val_tpl": "{{ value_json.voltage }}", "device": { "identifiers": [ "XXX-0" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX-0" } }
path: homeassistant/sensor/shellyplus2pm-XXX-1/voltage/config
payload:
{ "name": "shellyplus2pm-XXX Voltage 1", "~": "shellyplus2pm-XXX/", "stat_t": "~status/switch:1", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus2pm-XXX-1-voltage", "qos": 0, "dev_cla": "voltage", "stat_cla": "measurement", "unit_of_meas": "V", "val_tpl": "{{ value_json.voltage }}", "device": { "identifiers": [ "XXX-1" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX-1" } }
path: homeassistant/sensor/shellyplus2pm-XXX-0/power/config
payload:
{ "name": "shellyplus2pm-XXXPower 0", "stat_t": "~status/switch:0", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus2pm-XXX-0-power", "qos": 0, "~": "shellyplus2pm-XXX/", "dev_cla": "power", "stat_cla": "measurement", "unit_of_meas": "W", "val_tpl": "{{ value_json.apower }}", "device": { "identifiers": [ "XXX-0" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX-0" } }
path: homeassistant/sensor/shellyplus2pm-XXX-1/power/config
payload:
{ "name": "shellyplus2pm-XXXPower 1", "stat_t": "~status/switch:1", "frc_upd": "false", "enabled_by_default": true, "uniq_id": "shellyplus2pm-XXX-1-power", "qos": 0, "~": "shellyplus2pm-XXX/", "dev_cla": "power", "stat_cla": "measurement", "unit_of_meas": "W", "val_tpl": "{{ value_json.apower }}", "device": { "identifiers": [ "XXX-1" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX-1" } }
path: homeassistant/sensor/shellyplus2pm-XXX-0/energy/config
payload:
{ "name": "shellyplus2pm-XXXEnergy 0", "stat_t": "~status/switch:0", "frc_upd": "false", "enabled_by_default": false, "uniq_id": "shellyplus2pm-XXX-0-energy", "qos": 0, "~": "shellyplus2pm-XXX/", "dev_cla": "energy", "stat_cla": "total_increasing", "unit_of_meas": "Wh", "val_tpl": "{{ value_json['aenergy'].total|float/60)|round(2) }}", "device": { "identifiers": [ "XXX-0" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX-0" } }
path: homeassistant/sensor/shellyplus2pm-XXX-1/energy/config
payload:
{ "name": "shellyplus2pm-XXXEnergy 1", "stat_t": "~status/switch:1", "frc_upd": "false", "enabled_by_default": false, "uniq_id": "shellyplus2pm-XXX-1-energy", "qos": 0, "~": "shellyplus2pm-XXX/", "dev_cla": "energy", "stat_cla": "total_increasing", "unit_of_meas": "Wh", "val_tpl": "{{ value_json['aenergy'].total|float/60)|round(2) }}", "device": { "identifiers": [ "XXX-1" ], "manufacturer": "Shelly", "model": "shellyplus2pm", "name": "shellyplus2pm-XXX-1" } }
path: homeassistant/cover/shellyplus2pm-XXX-roller-0/config
payload:
{ "name": "shellyplus2pm-XXX Roller 0", "enabled_by_default": false, "cmd_t": "~rpc", "pl_open": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.Open\",\"params\":{\"id\":0}}", "pl_cls": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.Close\",\"params\":{\"id\":0}}", "pl_stop": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.Stop\",\"params\":{\"id\":0}}", "stat_t": "~status/cover:0", "value_template": "{{ value_json.state }}", "state_closing": "closing", "state_opening": "opening", "state_open": "open", "state_stopped": "stopped", "state_closed": "closed", "pos_t": "~status/cover:0", "pos_tpl": "{{ value_json.current_pos }}", "pos_open": 100, "pos_clsd": 0, "uniq_id": "shellyplus2pm-XXX-roller-0", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "qos": 1, "~": "shellyplus2pm-XXX/" }
path: homeassistant/cover/shellyplus2pm-XXX-roller-pos/config
payload:
{ "name": "shellyplus2pm-XXX Roller Pos", "enabled_by_default": false, "cmd_t": "~rpc", "pl_open": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.Open\",\"params\":{\"id\":0}}", "pl_cls": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.Close\",\"params\":{\"id\":0}}", "pl_stop": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.Stop\",\"params\":{\"id\":0}}", "stat_t": "~status/cover:0", "value_template": "{{ value_json.state }}", "state_closing": "closing", "state_opening": "opening", "state_open": "open", "state_stopped": "stopped", "state_closed": "closed", "pos_t": "~status/cover:0", "pos_tpl": "{{ value_json.current_pos }}", "pos_open": 100, "pos_clsd": 0, "set_pos_t": "~rpc", "set_pos_tpl": "{\"id\":0,\"src\":\"domoticz\",\"method\":\"Cover.GoToPosition\",\"params\":{\"id\":0,\"pos\": {{ position }} }}", "uniq_id": "shellyplus2pm-XXX-roller-pos", "avty_t": "~online", "pl_avail": "true", "pl_not_avail": "false", "qos": 1, "~": "shellyplus2pm-XXX/" }
path: shellyplus2pm-XXX/events/rpc
payload:
{ "src": "shellyplus2pm-XXX", "dst": "shellyplus2pm-XXX/events", "method": "NotifyStatus", "params": { "ts": 1692224760.01, "cover:0": { "id": 0, "aenergy": { "by_minute": [ 0, 0, 0 ], "minute_ts": 1692224759, "total": 6.05 } } } }
path: shellyplus2pm-XXX/status/cover
payload:
{ "id": 0, "source": "limit_switch", "state": "closed", "apower": 0, "voltage": 232.6, "current": 0, "pf": 0, "freq": 50, "aenergy": { "total": 6.05, "by_minute": [ 0, 0, 0 ], "minute_ts": 1692224819 }, "temperature": { "tC": 55, "tF": 130.9 }, "pos_control": true, "last_direction": "close", "current_pos": 0 }
This is all the information I could extract from MQTT Explorer.
I hope this is the desired information.
The only devices which have been created in Domoticz are roller-0, roller-pos, input 0, input 1, relay 0 and relay 1.
Yes, these are very detailed infos thank you!
But "shellyplus2pm-XXX/status/cover" path at the end is "shellyplus2pm-XXX/status/cover:0" with 0 at the end, isnt it?
If there are no status/switch:0 and status/switch:1 path in cover mode, than it makes sense that the devices which is bond to it will not appear under Domoticz. I have to add some new lines for "status/cover" or "status/cover:0" into templates.txt
"shellyplus2pm-XXX/status/cover" path at the end is indeed "shellyplus2pm-XXX/status/cover:0" with 0 at the end yes, sorry typo
in path shellyplus2pm-XXX/status/ there is only cover:0 indeed. But since this device can be used as double switch OR as cover I can imagine that lines are necessary for both switch and cover.
The Sensor devices (temperature, voltage, power and energy) are not being created in Domoticz as device by the way.
If you need any more information please let me know!
Thanks, i've added new sensors into mqtt_templates_gen2.txt you can download the new version now: https://raw.githubusercontent.com/enesbcs/shellyteacher4domo/f359a6b725862c2a42233ae96969d0d47fc6f287/mqtt_templates_gen2.txt
Great work! thanks.
Now I have also Voltage, Energy and Power, my blinds are reacting to open/close/stop command base on "shellyplus2pm-XXX-roller-0/shellyplus2pm-XXXRoller 0 (unique_id: shellyplus2pm-XXX-roller-0)" device in Domoticz. roller-pos doesn't work yet.
something else strange, in the logging I see:
2023-08-17 21:49:15.154 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX/shellyplus2pm-XXX Relay 0 (unique_id: shellyplus2pm-XXX-0) 2023-08-17 21:49:15.255 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX/shellyplus2pm-XXX Input 0 (unique_id: shellyplus2pm-XXX-0-input) 2023-08-17 21:49:15.357 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-temperature-0/shellyplus2pm-XXX Temperature 0 (unique_id: shellyplus2pm-XXX-temperature-0) 2023-08-17 21:49:15.457 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-0/shellyplus2pm-XXX Voltage 0 (unique_id: shellyplus2pm-XXX-0-voltage) 2023-08-17 21:49:15.558 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-0/shellyplus2pm-XXX Power 0 (unique_id: shellyplus2pm-XXX-0-power) 2023-08-17 21:49:15.659 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-0/shellyplus2pm-XXX Energy 0 (unique_id: shellyplus2pm-XXX-0-energy) 2023-08-17 21:49:15.760 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-1/shellyplus2pm-XXX Relay 1 (unique_id: shellyplus2pm-XXX-1) 2023-08-17 21:49:15.861 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-1-input/shellyplus2pm-XXX Input 1 (unique_id: shellyplus2pm-XXX-1-input) 2023-08-17 21:49:15.962 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-temperature-1/shellyplus2pm-XXX Temperature 1 (unique_id: shellyplus2pm-XXX-temperature-1) 2023-08-17 21:49:16.063 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-1/shellyplus2pm-XXX Voltage 1 (unique_id: shellyplus2pm-XXX-1-voltage) 2023-08-17 21:49:16.165 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-1/shellyplus2pm-XXX Power 1 (unique_id: shellyplus2pm-XXX-1-power) 2023-08-17 21:49:16.266 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-1/shellyplus2pm-XXX Energy 1 (unique_id: shellyplus2pm-XXX-1-energy) 2023-08-17 21:49:16.367 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-roller-0/shellyplus2pm-XXX Roller 0 (unique_id: shellyplus2pm-XXX-roller-0) 2023-08-17 21:49:16.469 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-roller-pos/shellyplus2pm-XXX Roller Pos (unique_id: shellyplus2pm-XXX-roller-pos) 2023-08-17 21:49:16.570 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-roller-0-temperature/shellyplus2pm-XXX Roller Temperature 0 (unique_id: shellyplus2pm-XXX-roller-0-temperature) 2023-08-17 21:49:16.671 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-roller-0/shellyplus2pm-XXX Roller Voltage 0 (unique_id: shellyplus2pm-XXX-roller-0-voltage) 2023-08-17 21:49:16.771 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-roller-0/shellyplus2pm-XXX Roller Power 0 (unique_id: shellyplus2pm-XXX-roller-0-power) 2023-08-17 21:49:16.872 Status: MQTT Auto Discovery: discovered: shellyplus2pm-XXX-roller-0/shellyplus2pm-XXX Roller Energy 0 (unique_id: shellyplus2pm-XXX-roller-0-energy)
In Domoticz I see only Roller Voltage 0, Roller Temperature 0, Roller Power 0, Roller Energy 0, roller pos, roller 0, input 0, input 1, relay 0 and relay 1 as created devices..
There is no device being created for Roller Voltage 1, Roller Temperature 1, Roller Power 1, Roller Energy 1. Does this work as designed? Or should there be number 1 devices?
Now I have also Voltage, Energy and Power, my blinds are reacting to open/close/stop command base on "shellyplus2pm-XXX-roller-0/shellyplus2pm-XXXRoller 0 (unique_id: shellyplus2pm-XXX-roller-0)" device in Domoticz. roller-pos doesn't work yet. For some reason if setposition topic is added to a cover device, Domoticz does not use the open/close/stop commands, only the position, this is the reason why i added two distinct devices, and this is the reason why it wont work until you apply setposition fix to shelly device.
"shellyplus2pm-XXX Roller 0" havent got the ability to set position and never will.
"shellyplus2pm-XXX Roller Pos" is the one which has to be enabled first in the Domoticz device list, and after you have to upload and set autostart the javascript fix https://raw.githubusercontent.com/enesbcs/shelly-script-examples/main/shelly2p-domo-coverfix.js and after applying it to the 2PM it will able to handle commands which Domoticz sends to "shellyplus2pm-XXX/rpc"
something else strange, in the logging I
In Domoticz I see only Roller Voltage 0, Roller Temperature 0, Roller Power 0, Roller Energy 0, roller pos, roller 0, input 0, input 1, relay 0 and relay 1 as created devices..
I do not see anything strange on that list. As i said multiple time, only the devices which sends values will be created by Domoticz, it does not matter how many /config templates arrives to Domo. I can't explain it any simpler than that.
There is no device being created for Roller Voltage 1, Roller Temperature 1, Roller Power 1, Roller Energy 1. Does this work as designed? Or should there be number 1 devices?
There are only 1 roller device exists on 2PM and its name is "cover:0"
ok, I clear for me now, didn't understand what u were saying, but now I do. No data is no device and appently these devices don't have any data.
Clear on roller-0, only open/close/stop, this is working correctly.
I have added the script to ShellyPlus2PM, script saved and activated.
When starting the script, it runs for a fraction of a second and then stops.
Tried in Domoticz with device roller-pos to change the slider from 100% to for example 44% but nothing happens.
This is what I see in Domoticz log:
2023-08-18 12:37:55.999 MQTT Auto Discovery: Light/Switch/Switch (shellyplus2pm-90380c38560c Roller Pos) 2023-08-18 12:37:55.996 Status: User: Xavier (IP: 192.168.0.133) initiated a switch command (487/shellyplus2pm-90380c38560c Roller Pos/Set Level)
Reading this thread (open issue) here I can read your post of Jul 8 that is has to be fixed by Domoticz, but not in the near future and you suggest to use the script in the Shelly.
What am I doing wrong why this is not working?
I have added the script to ShellyPlus2PM, script saved and activated. When starting the script, it runs for a fraction of a second and then stops. Tried in Domoticz with device roller-pos to change the slider from 100% to for example 44% but nothing happens. This is what I see in Domoticz log:
2023-08-18 12:37:55.999 MQTT Auto Discovery: Light/Switch/Switch (shellyplus2pm-90380c38560c Roller Pos) 2023-08-18 12:37:55.996 Status: User: Xavier (IP: 192.168.0.133) initiated a switch command (487/shellyplus2pm-90380c38560c Roller Pos/Set Level)
Did you check with MQTT Explorer what Domoticz sent to device /rpc MQTT channel when clicking on Domoticz slider?
Reading this thread (open issue) here I can read your post of Jul 8 that is has to be fixed by Domoticz, but not in the near future and you suggest to use the script in the Shelly.
What am I doing wrong why this is not working?
Yes, you need to debug the script. On your Shelly try to enable Settings/Debug "Websocket debug" checkbox than go Scripts open your script and check "FULL LOG" at the Console on the bottom. It will give you detailed informations. This is mine Shelly 1 Plus debug informations when running the fix:
shelly_user_script.:423 Running 'script_1.js'...
shelly_user_script.:395 mJS RAM stat: after user code: 141576 after: 130024, used: 11552
shelly_notification:161 Status change of script:1: {"id":1,"running":true}
mg_rpc.c:314 Shelly.GetDeviceInfo via loopback
mgos_mqtt_conn.c:169 MQTT0 sub shellyplus1-xxx/rpc @ 1
shelly_mqtt_script_:112 MQTT subscribed to shellyplus1-xxx/rpc
It says that its succesfully subscribed to /rpc path and awaits commands.
checked MQTT Explorer:
when sliding in Domoticz with device Roller pos to 15% then I see in MQTT Explorer in path /shellyplus2pm-XXX/rpc:
{ "id:0,src:domoticz,method:Cover.GoToPosition,params:id:0,pos: position": 15 }
So from Domoticz the message goes to the Shelly but the cover/blind is not moving to 15%. I also tested what happens when I change the slider in de GUI of the shellyplus2pm itself, then the sliders are updated with the same percentage as in the Shelly GUI.
This is the output/debug of Shellyplus2pm script:
shelly_notification:163 Status change of cover:0: {"id":0,"aenergy":{"by_minute":[166.907,0.000,0.000],"minute_ts":1692357299,"total":7.874}} 13:15:00 shos_sntp.c:84 New SNTP time: 1692357305.263958 (delta -0.042548) 13:15:05 shelly_sys.cpp:202 Time is set 13:15:05 shos_rpc_inst.c:230 script.list via WS_in 192.168.0.197:2031 13:15:05 shos_rpc_inst.c:230 script.start via WS_in 192.168.0.197:2031 13:15:05 shelly_user_script.:331 JS RAM stat: initial: 100120 after: 100092, used: 28 13:15:05 shelly_user_script.:370 Running 'script_1.js'... 13:15:05 shelly_ejs_rpc.cpp:41 Shelly.call Shelly.GetDeviceInfo {} 13:15:05 shelly_user_script.:341 JS RAM stat: after user code: 100120 after: 97896, used: 2224 13:15:05 shelly_notification:163 Status change of script:1: {"id":1,"running":true} 13:15:05 shos_rpc_inst.c:230 Shelly.GetDeviceInfo via loopback 13:15:05 Uncaught SyntaxError: Expecting a valid value, got EOF 13:15:05 at line 1 col 1 13:15:05 13:15:05 ^ 13:15:05 in function called from system 13:15:05 13:15:05 shelly_user_script.:400 syntax_error: Error in EjsCall 13:15:05 shelly_notification:163 Status change of script:1: {"id":1,"errors":["syntax_error"],"running":false} 13:15:05
The IP-address in the log "192.168.0.197" is my own windows machine from which the command is sent.
checked MQTT Explorer: when sliding in Domoticz with device Roller pos to 15% then I see in MQTT Explorer in path /shellyplus2pm-XXX/rpc:
{ "id:0,src:domoticz,method:Cover.GoToPosition,params:id:0,pos: position": 15 }
Yep the MQTT part works. (semantically not good, but at least it contains the data)
Uncaught SyntaxError: Expecting a valid value, got EOF 13:15:05 at line 1 col 1 13:15:05
Well this means that you have a problem in Line 1 at the first character so something is really messed up. Did you copy+paste the code through or downloaded from github and uploaded to Shelly? if you are not used the raw version of the JS script it may contain HTML codes which makes shelly unable to start it.. or if line endings disappeared or non-wanted special characters appeared in the code. A lots of problems can occur...
This is how the code should be formatted, after inserting inside Shelly: Every { and } and ; matters...
let CONFIG = {
shelly_id: null,
};
Shelly.call("Shelly.GetDeviceInfo", {}, function (result) {
CONFIG.shelly_id = result.id;
MQTT.subscribe(
buildMQTTStateCmdTopics("rpc"),
DecodeDomoticzFaultyJSON
);
});
function buildMQTTStateCmdTopics(topic) {
let _t = topic || "";
return CONFIG.shelly_id + "/" + _t;
}
/**
* @param {string} topic
* @param {string} message
*/
function DecodeDomoticzFaultyJSON(topic, message) {
let req = JSON.parse(message);
let r;
for (r in req){
if (r.indexOf("GoToPosition") > 1) { // if Json contains GoToPosition then do that!
SetCoverPosition(req[r]);
break;
}
}
}
function SetCoverPosition(position) {
Shelly.call("Cover.GoToPosition", {
id: 0,
pos: position,
});
}
I copied the exact code.
I went to shelly/script
created new script
pasted the code
saved the code
started the script
runs shortly (less then a second) and stops
this is the debug logging I get:
Uncaught SyntaxError: Expecting a valid value, got EOF 14:03:27 at line 1 col 1 14:03:27 14:03:27 ^ 14:03:27 in function called from system 14:03:27 14:03:27 shelly_user_script.:400 syntax_error: Error in EjsCall
checked MQTT Explorer: when sliding in Domoticz with device Roller pos to 15% then I see in MQTT Explorer in path /shellyplus2pm-XXX/rpc:
{ "id:0,src:domoticz,method:Cover.GoToPosition,params:id:0,pos: position": 15 }
Yep the MQTT part works. (semantically not good, but at least it contains the data)
Uncaught SyntaxError: Expecting a valid value, got EOF 13:15:05 at line 1 col 1 13:15:05
Well this means that you have a problem in Line 1 at the first character so something is really messed up. Did you copy+paste the code through or downloaded from github and uploaded to Shelly? if you are not used the raw version of the JS script it may contain HTML codes which makes shelly unable to start it.. or if line endings disappeared or non-wanted special characters appeared in the code. A lots of problems can occur...
I copied the code from raw: https://raw.githubusercontent.com/enesbcs/shelly-script-examples/main/shelly2p-domo-coverfix.js and pasted it into shelly script
Got it to work with this code:
`let CONFIG = { shelly_id: null, };
Shelly.call("Shelly.GetDeviceInfo", {}, function (result) { if (result && result.id) { CONFIG.shelly_id = result.id; MQTT.subscribe( buildMQTTStateCmdTopics("rpc"), DecodeDomoticzFaultyJSON ); } else { console.log("Failed to get Shelly device info:", result); } });
function buildMQTTStateCmdTopics(topic) { let _t = topic || ""; return CONFIG.shelly_id + "/" + _t; }
/**
function SetCoverPosition(position) { Shelly.call("Cover.GoToPosition", { id: 0, pos: position, }); }`
code is not getting correctly here :( I made a pull-request with the code above ;) renamed the file to "shelly2p-domo-coverfixv2.js"
Interesting.. i am using v0.14.1 firmware but try {} is not supported, your code are unable to start for me.
MJS error: [try] is not implemented
But this code works:
let CONFIG = {
shelly_id: null,
};
Shelly.call("Shelly.GetDeviceInfo", {}, function (result) {
if (result && result.id) {
CONFIG.shelly_id = result.id;
MQTT.subscribe(
buildMQTTStateCmdTopics("rpc"),
DecodeDomoticzFaultyJSON
);
} else {
console.log("Failed to get Shelly device info:", result);
}
});
function buildMQTTStateCmdTopics(topic) {
let _t = topic || "";
return CONFIG.shelly_id + "/" + _t;
}
/**
* @param {string} topic
* @param {string} message
*/
function DecodeDomoticzFaultyJSON(topic, message) {
let trimmedMessage = message.trim();
if (trimmedMessage) {
let req = JSON.parse(trimmedMessage);
for (let r in req) {
if (r.indexOf("GoToPosition") !== -1) { // Check if "GoToPosition" is present in the key
SetCoverPosition(req[r]);
break;
}
}
}
}
function SetCoverPosition(position) {
Shelly.call("Cover.GoToPosition", {
id: 0,
pos: position,
});
}
I'm on 1.0.0 firmware version for ShellyPlus2PM....
I'm on 1.0.0 firmware version for ShellyPlus2PM....
OK, i see there is a 1.0.0-beta firmware, checking now. (0.14.1 is the last stable)
Thank you for debugging and testing @Xavier82!
This is the fixed version for stable Shelly firmware: https://github.com/enesbcs/shelly-script-examples/blob/main/shelly2p-domo-coverfix.js
And this is the try-catch version for >=1.0.0 Shelly firmware: https://github.com/enesbcs/shelly-script-examples/blob/main/shelly2p-domo-coverfix-v2.js
no problem! Thank you for your time and patience. After the weekend I will convert my shelly gen 1 devices with your old shelly mqtt python to this new proces based on auto discover, so maybe I contact you again when I find issues ;)
I hope most functions will work for your gen1 devices, as scripting can only help us on gen2 devices!
I guess this issue can be closed? Or still waiting for Domoticz team to solve things?
I hope someday Domoticz has proper template support. Until that i think its fixed from our side. Entry added to the wiki: https://github.com/enesbcs/shellyteacher4domo/wiki/Shelly-2PM-Cover-Position
I guess this issue can be closed? Or still waiting for Domoticz team to solve things?
@Xavier82 Latest Domoticz 2023 beta added support for simple set_pos_tpl property and a new "Roller Pos (MqttControl)" device added to latest Teacher templates if you want to test it: https://github.com/enesbcs/shellyteacher4domo/commit/d4da33ad46197b03d29cefe553bc82cee8df807e
No fix needed, as not using JSON output in this solution, just simple text. MQTT Control has to be enabled in Shelly2PM MQTT settings page on the device of course.
Hi @enesbcs I need to test this.
I also saw on Domoticz Github the following fix: https://github.com/domoticz/domoticz/commit/8272d4c8f93f96f268b86697a03c7244d4c7fcb5
Does this reflect on this issue?
Hi @enesbcs I need to test this.
I also saw on Domoticz Github the following fix: https://github.com/domoticz/domoticz/commit/8272d4c8f93f96f268b86697a03c7244d4c7fcb5
Does this reflect on this issue?
Yes! Since 0.14.0 there is a feature in Gen2 devices named "MQTT Control". https://shelly-api-docs.shelly.cloud/gen2/ComponentsAndServices/Cover/#mqtt-control
It does not need a JSON structure anymore, just pure text commands, such as:
topic: ~command/cover:0 payload: pos,50
So a new config topic was added to ShellyTeacher and the above fix in Domoticz added support for this.
ok, great and good to hear. So this is the final fix for cover mode, no JSON/script is needed on Shelly itself and this is fixed in DOmoticz beta and fixed in ShellyTeacher4Domo. Do I need te rediscover with shellyteacher4domo for this new MQTT control?
Do I need te rediscover with shellyteacher4domo for this new MQTT control?
Yes, unless you send the new config object to the mqtt broker manually.
updated Shellyteacher4domo, for my Shelly2PM Gen2 (in roller mode) 1 extra device has been created and is working now. So seems that the additionally extra script code in Shelly is not necessary anymore.
Good news! Thank you for testing!
Cover device does not have set_position_topic (shellyplus2pm-441793ceb570-roller-0/NEW
The 0% and 100% for open and close are working fine.