Closed pascalsaul closed 6 years ago
This should work. What's your version of pimatic-mqtt?
mqtt 0.9.5 and now 0.9.6 after update ;) Still the same problem though.
Hi, I probably do not get the question. Because the switch has a configurable payload.
Turn switch ON: cmnd/basic/POWER 1 stat/basic/RESULT {"POWER":"1"} stat/basic/POWER 1
Turn switch OFF: cmnd/basic/POWER 0 stat/basic/RESULT {"POWER":"0"} stat/basic/POWER 0
I could use the values ON (1) and OFF (0) it works when I switch the device through Pimatic.
When I switch the device with the physical button it only sends out the State information: stat/basic/RESULT {"POWER":"1"} stat/basic/POWER 1 stat/basic/RESULT {"POWER":"0"} stat/basic/POWER 0
In Pimatic it doesn't switch the state to ON or OFF when I use the values ON and OFF. So it does work when I use the 0 and 1 values by the 'cmnd' and 'stat' switched through Pimatic or physical.
When I use ON and OFF and only works with Pimatic. When I switch the device with the physical button then there is a synchronisation mismatch. Pimatic still thinks the device is ON when I turn it off with the physical button. I hope this makes the issue more clear to you.
If you say auto translating should work also for the State then there is a bug somewhere. That's the reason I've asked to make it configurable because now I changed the firmware in the device to send out a 0 or 1.
The switch expects the device send its status in the same form it listens to.
this configurations works:
{
"id": "test-switch",
"name": "test-switch",
"class": "MqttSwitch",
"topic": "cmnd/basic/POWER",
"stateTopic": "stat/basic/POWER",
"qos": 0,
"onMessage": "1",
"offMessage": "0"
}
On the state topic, it expects 1/0
or
{
"id": "test-switch",
"name": "test-switch",
"class": "MqttSwitch",
"topic": "cmnd/basic/POWER",
"stateTopic": "stat/basic/POWER",
"qos": 0,
"onMessage": "ON",
"offMessage": "OFF"
}
On the state topic, it expects ON/OFF
It is pointless for the device to send a different message form for the control and state.
Absolute true but can you tell me why I need to specify the ON/OFF message when my device is outputting ON/OFF but not when it outputs 1/0. I don't get it, sorry. And it's only when switching the device manually with the ON/OFF outputs.
The fix for me that works it to let the device send out 1 or 0. In the ideal world it should be working with ON/OFF also. Somewhere there is a bug or something really weird.
mosquitto_pub -t 'cmnd/basic/StateText1' -m 'OFF' mosquitto_pub -t 'cmnd/basic/StateText2' -m 'ON'
State hardcoded in Pimatic device and switched manual = OK stat/basic/RESULT {"POWER":"ON"} stat/basic/POWER ON stat/basic/RESULT {"POWER":"OFF"} stat/basic/POWER OFF
State hardcoded in Pimatic device and switched through Pimatic = OK cmnd/basic/POWER ON stat/basic/RESULT {"POWER":"ON"} stat/basic/POWER ON cmnd/basic/POWER OFF stat/basic/RESULT {"POWER":"OFF"} stat/basic/POWER OFF
State untouched and switched through Pimatic = OK cmnd/basic/POWER 1 stat/basic/RESULT {"POWER":"ON"} stat/basic/POWER ON cmnd/basic/POWER 0 stat/basic/RESULT {"POWER":"OFF"} stat/basic/POWER OFF
State untouched and switched manual = NOT OK stat/basic/RESULT {"POWER":"ON"} stat/basic/POWER ON stat/basic/RESULT {"POWER":"OFF"} stat/basic/POWER OFF
Pimatic device without state:
{ "topic": "cmnd/basic/POWER", "stateTopic": "stat/basic/POWER", "qos": 2, "retain": true, "id": "basic", "name": "Basic", "class": "MqttSwitch" }
Pimatic device with state:
{ "topic": "cmnd/basic/POWER", "stateTopic": "stat/basic/POWER", "qos": 2, "retain": true, "id": "basic", "name": "Basic", "class": "MqttSwitch", "onMessage": "ON", "offMessage": "OFF" },
Working config for me: cmnd/basic/StateText2 1 stat/basic/RESULT {"StateText2":"1"} cmnd/basic/StateText1 0 stat/basic/RESULT {"StateText1":"0"}
Turned on with Pimatic: cmnd/basic/POWER 1 stat/basic/RESULT {"POWER":"1"} stat/basic/POWER 1
Turned off manually: stat/basic/RESULT {"POWER":"0"} stat/basic/POWER 0
Device in Pimatic is default:
{ "topic": "cmnd/basic/POWER", "stateTopic": "stat/basic/POWER", "qos": 2, "retain": true, "id": "Basic", "name": "Basic", "class": "MqttSwitch" },
Absolute true but can you tell me why I need to specify the ON/OFF message when my device is outputting ON/OFF but not when it outputs 1/0.
Because 1 and 0 are default values.
Tasmota uses ON and OFF for the state messages for the power state of switches. pimatic-mqtt parses 0 or 1 as state for devices. This probably should be made configurable with the default of 0 or 1, but it should be possible to override the default values because not every firmware will implement the same standard.
Tasmota's firmware send the following message on the bus: cmnd/th01/POWER = OFF/ON stat/th01/POWER = OFF/ON
Pimatic only recognises a 1 or 0 as state instead of automatically translating the commands OFF/ON as 0/1. Sending stat/th01/POWER = 0/1 does work