Hey all, Just got a question about the interaction of the payload_on, payload_off and value_template
I need to publish to control it:
publish (command) “{‘POWER’ : ‘ON’}”
I have a device that will publish something like:
publish (state) “{‘POWER’ : ‘ON’, ‘XXX’ : ‘42’, ‘YYY’ : ‘VAL’}”
So, the device might publish some other data in the response.
I was wondering how to specify this in the MQTT switch? Does the value_template apply to the command and the state or just the state? What about the payload on and off???
I need to pass a timestamp in the payload value but it does not get interpreted and in the actual payload I have the Json {"value":"OFF","since":"{{ as_timestamp(now())|round|int }}"}
I believe payload_on and payload_off don’t accept templates.
MQTT switch provides value_template for processing the received payload. However, it doesn’t have an equivalent command_template for processing the transmitted payload. It ‘hard-codes’ the transmitted payload via payload_on and payload_off.
Here’s one way to do it. Change the switch’s command_topic to something else like plug/1/setstate then create an automation that triggers on that topic and republishes its payload, with an added timestamp, to servicelocation/UUID/plug/1/setstate.