as per this discussion it’s not always possible because of high power consumption and difficulty of deep sleep stuff.
I did it quite straightforward. This bit is specific to RFLink that creates sensors with generated names.
# it uses the fact that rflink creates sensor.xxx_update_time
# and updates its value every time new readings (_temp and _hum) arrive
# so we can find out the original sensors' names
# and copy their values into the target sensors (all temperature, humidity and update_time)
# that means the target sensors are updated every time, not only when it's changed!
- alias: sensor_thb_rflink_route_value_to_entity
trigger:
platform: state
entity_id:
- sensor.dummy_update_time
# reception
# lounge
# kitchen
action:
service: python_script.sensor_thb_rflink_route_value_to_entity
data_template:
object_id : "{{ trigger.to_state.object_id }}"
value : "{{ trigger.to_state.state }}"
and then
arg = 'object_id'
object_id = data.get(arg)
assert object_id, "Please specify %s!" % arg
arg = 'value'
value = data.get(arg)
assert value, "Please specify %s!" % arg
arg = 'force_update'
force_update = data.get(arg, 'True').lower() == 'true'
update_time_suffix = '_update_time'
# figure out the base name if the sensor from object_id
base_object_id = object_id.replace(update_time_suffix, '')
known_sensors = {
'prologue_97b0' : 'rflink_ground_floor_reception',
'prologue_9100' : 'rflink_ground_floor_lounge',
'prologue_9440' : 'rflink_ground_floor_kitchen'
}
if base_object_id in known_sensors:
cmd = 'set_state'
attr_entity_id = 'entity_id'
attr_state = 'state'
all_siffixes = {
'temp': 'temperature',
'hum': 'humidity'
}
for source_suffix, target_suffix in all_siffixes.items():
source_entity_id = "sensor.{}_{}".format(base_object_id, source_suffix)
source_object = hass.states.get(source_entity_id)
assert source_object, "Cannot find %s" % source_entity_id
source_value = source_object.state
target_entity_id = "sensor.{}_{}".format(known_sensors[base_object_id], target_suffix)
# update state only if it's different
if not force_update:
target_object = hass.states.get(target_entity_id)
assert target_object, "Cannot find %s" % target_entity_id
targer_value = target_object.state
if source_value == targer_value:
logger.debug("%s: state (%s) is the same, not updating", target_entity_id, source_value)
continue
logger.debug("%s(%s: %s, %s: %s)", cmd, attr_entity_id, target_entity_id, attr_state, source_value)
hass.services.call('python_script', cmd, {attr_entity_id: target_entity_id, attr_state: source_value} )
# and finally set state of the target _update_time sensor as we have the source value already and it should be always updated (as it's always different)
target_entity_id = "sensor.{}{}".format(known_sensors[base_object_id], update_time_suffix)
logger.debug("%s(%s: %s, %s: %s)", cmd, attr_entity_id, target_entity_id, attr_state, value)
hass.services.call('python_script', cmd, {attr_entity_id: target_entity_id, attr_state: value} )
else:
logger.warning("sensor.%s not configured", base_object_id)
With OMG Pilight it’s slightly easier as I only need to add a new ID to a python script
id = int(float(data.get('id', -1)))
temperature = data.get('temperature')
humidity = data.get('humidity')
battery = data.get('battery')
known_entities = {
39 : 'ground_floor_reception',
16 : 'ground_floor_lounge',
68 : 'ground_floor_kitchen'
}
if id in known_entities.keys():
hass.services.call(
'python_script',
'sensor_thb_pilight_set_values',
{
'object_id_prefix' : "sensor_pilight_{}_".format(known_entities[id]),
'temperature' : temperature,
'humidity' : humidity,
'battery' : battery
}
)
else:
logger.warning("id %i not configured", id)