Although the solution I offered many months ago does work, I would now suggest a completely different one. It’s simpler to implement, easier to manage, and doesn’t require the use of input_booleans.
I recommend Strategy #2 in this post: Sonoff RF Bridge. Strategies for receiving data. It uses the concept of demultiplexing (demux).
The solution consists of:
- One simple automation
- One simple python_script
The configuration of each MQTT Binary Sensor is greatly simplified. It doesn’t even need a value_template
.
For example, this is how simple they become when using Strategy #2:
- platform: mqtt
name: 'Cave Door'
state_topic: 'home/sensor1'
device_class: door
- platform: mqtt
name: 'Garage Door'
state_topic: 'home/sensor2'
device_class: garage_door
The only work you have to perform is configuring the JSON dictionary within the python_script (see the linked post for complete instructions).
For example, this is how it would be defined for @Lefuneste’s two binary_sensors:
d = { '31D20A':['sensor1','ON','true'],
'31D20E':['sensor1','OFF','true'],
'32BB0A':['sensor2','ON','true'],
'32BB0E':['sensor2','OFF','true']
}
The true
you see there means the payload (ON
or OFF
) is published as a retained message. That means the binary_sensor’s state is stored by the MQTT broker so when Home Assistant restarts, it acquires the sensor’s latest state from the broker.
Adding another binary_sensor becomes child’s play:
Step 1: Define it.
- platform: mqtt
name: 'Kitchen Window'
state_topic: 'home/sensor3'
device_class: window
Step 2: Append its RF codes to the JSON dictionary in the python_script.
d = { '31D20A':['sensor1','ON','true'],
'31D20E':['sensor1','OFF','true'],
'32BB0A':['sensor2','ON','true'],
'32BB0E':['sensor2','OFF','true'],
'36DE0A':['sensor3','ON','true'],
'36DE0E':['sensor3','OFF','true']
}
Step 3: Restart Home Assistant.