Whilst I realise this is quite an old thread, I thought I would leave my own take on the strategy 2 python_script approach for demux’ing the signals.
It is basically the same as main script with a little extra hack added to support automatic home assistant MQTT discovery, so it is a little easier to manage as you don’t need to worry about manually creating (or recreating) the sensors. Just add them to the script, trigger them once and away you go .
I have used this in a few setups for friends (so comments in the code ) with several bridges who had a need to use a load of existing 433 sensors.
# Script to demux the RF codes received on MQTT topics from the bridge and send them back to new topics and automatically setup them as sensors in HA.
# Tested with Sonoff RF bridges with Tasmota but the logic will work with any RF bridge that exposes to MQTT.
# You can get your codes by looking at the Console log on any of your RF Bridges as devices are triggered.
# If you want to support multiple RF bridges you can either have them all post to the same MQTT topic (a tiny bit more efficient BUT you can't tell the bridge messages apart)
# or just set this script up to trigger on each topic individually.
# Only support for simple Binary Sensors right now.
# TODO: Expand to add discovery/setup for switches and the right command_topic for the bridge.
# Adapted from the scripts kindly posted to: https://community.home-assistant.io/t/sonoff-rf-bridge-strategies-for-receiving-data/108181
# Name that is used in the discovery node_id along with the construction of 'fake' model and manufacturer to make filtering discovered devices nice and easy.
FAKE_NAME = 'rfbridge'
# Topic Root - Just the root topic (with /) where you want your states published.
TOPIC_ROOT = 'internal/ha-rf433/'
# device_class MUST be valid for a Home Assistant Binary Sensor (see https://www.home-assistant.io/integrations/binary_sensor/)
#
# Try the following:
#
# 'light', 'power', 'plug', 'door', 'window', 'garage_door', 'lock'
# RF Codes and Setup Information:
#
# You need to setup the RF codes for your environment, names and some vanity settings in this part of the script.
# It is used to check for supported codes and also used to populate the MQTT discovery so that the devices pop up in
# Home Assistant the 1st time this script 'sees' the sensor.
#
# Format:
#
# RF Code (as seen by your bridge) : topic subname (also used in for discovery, use the same for both states),
# state (ON or OFF, repeat the complete line for both if your device has discreate commands for both),
# retain (true for saved state, false for unknown or single state), device_class
entities = {
'D3503B':['rf_dining_4_gang_extension_3','ON','true','power'],
'D3503A':['rf_dining_4_gang_extension_3','OFF','true','power'],
'A39C1B':['rf_dining_4_gang_extension_3','ON','true','power'],
'A39C1A':['rf_dining_4_gang_extension_3','OFF','true','power'],
'D3503F':['rf_dining_4_gang_extension_1','ON','true','power'],
'D3503E':['rf_dining_4_gang_extension_1','OFF','true','power'],
'D35037':['rf_dining_4_gang_extension_2','ON','true','power'],
'D35036':['rf_dining_4_gang_extension_2','OFF','true','power'],
'D35033':['rf_dining_4_gang_extension_4','ON','true','power'],
'D35032':['rf_dining_4_gang_extension_4','OFF','true','power'],
'33858F':['rf_lounge_strip','ON','true','light'],
'33858E':['rf_lounge_strip','OFF','true','light'],
'93620A':['door_sensor_1','ON','true','door'],
'9B620E':['door_sensor_1','OFF','true','door'],
}
# With some luck you should not need to edit below this point.
payload = data.get('payload')
if payload in entities:
try:
topic, state, retain, device_class = entities[payload]
except ValueError:
topic = '{0}unknown'.format(TOPIC_ROOT),
state = payload
retain = 'false'
device_class = 'unknown'
logger.warning(
'<rfbridge_demux> Received invalid RF command: {0}'.format(payload)
)
service_data = {
'topic': '{1}{0}'.format(topic, TOPIC_ROOT),
'payload': '{0}'.format(state),
'qos': 0,
'retain': '{0}'.format(retain),
}
discovery_data = {
'topic': 'homeassistant/binary_sensor/{1}/{0}/config'.format(topic, FAKE_NAME),
'payload': '{{"name": "{0}", "state_topic": "internal/ha-rf433/{0}", "device_class": "{1}", "unique_id": "{0}-{2}", "mdl": "{2}-{1}", "mf": "{2}" }}'.format(topic, device_class, FAKE_NAME),
'retain': 'true'
}
hass.services.call('mqtt', 'publish', service_data, False)
hass.services.call('mqtt', 'publish', discovery_data, False)
# Remove these last lines if you don't want to fill your log every time your bridge catches a code that you're not working with.
else:
logger.warning(
'<rfbridge_demux> Received unregistered RF command: {0}'.format(payload)
)