I have a device which is controlled via MQTT. It is very simple and has only two topics:
- aromadiffuser/command with values
press
for switch on andpress_long
for switch off - aromadiffuser/state where 3 possible values:
on
,off
anderror
(in case low level of water).
I want to have a switch in HA which will be show an error in case of error or current state of the device. And I need to have an ability to enabling and disabling it from HA with the same switch.
I am trying to implement it with this code:
switch:
- platform: template
switches:
aromadiffuser:
friendly_name: Aromadiffuser
value_template: '{{ value }}'
payload_on: "on"
payload_off: "off"
turn_on:
service: mqtt.publish
data:
topic: "aromadiffuser/command"
payload: "press"
turn_off:
service: mqtt.publish
data:
topic: "aromadiffuser/command"
payload: "press_long"
As I see it’s able to enable or disable the device but it doesn’t show any state of the device. How can I handle non-JSON state with 3 options?