I want to transfer status data of my switches from fhem to hassio using MQTT.
My issue: On each status change I get not only one message, but two. These are:
set_on
on
set_off
off
set_toogle
on or off, depending
I used the MQTT Switch - Home Assistant
switch:
- platform: mqtt
name: "Licht Aussen"
icon: mdi:lightbulb
state_topic: "fhem/licht/aussen/reading/state"
command_topic: "fhem/licht/aussen/state/set"
#availability_topic: "fhem/licht/aussen/available"
payload_on: "on"
payload_off: "off"
state_on: "on"
state_off: "off"
optimistic: false
qos: 0
retain: true
But it looks like each time hassio gets a content which is not âonâ it will be interpreted as off.
Anyway the result is, that the switch in hassio is switching finaly to off, regardless, what I am doing.
I used the MQTT.fx to monitor the content of MQTT messages. It looks like the command_topic should work. In MQTT.fx I can put on or off into the topic and it works.
In the documentation of switch.mqtt there is a
value_template
(string)(Optional)Defines a template to extract a value from the payload.
Maybe I can use this to filter out only on and off and to ignore all other content?
But I am completely new to hassio and I am a little bit overwelmed from the
Is this the right way?
And if yes, how I can use value_template to filter out only on and off?
there is something with value and value_jason, but I donât understand, how to start with this. Even this starting point from
is not clear for me:
This means that if the incoming values looks like the sample below:
{ "on": "true", "temp": 21 }
The template for on would be:
'{{value_json.on}}'
what shoul I use to reference the incomming state?
â{{value_json.state}}â
â{{value_json.state_topic}}â
???
My logic would be:
CASE WHEN topic_value IN (on, off) THEN use it ELSE ignore it END
or
CASE WHEN topic_value = on then on WHEN topic_value = off then off ELSE ignore it END