If you don’t like using an input_text for this purpose, the alternative is to use a sensor. However, there is no sensor.set_value
service in Home Assistant. That makes it challenging for the automation to assign a value to a sensor.
I know of two workarounds:
- If you’re already using MQTT, the automation can use
mqtt.publish
to set the sensor’s state. -
@rodpayne has created a python_script, called
set_state.py
, that can set a sensor’s state. The automation can usepython_script.set_state
to set the sensor’s state.
I’ve used the first workaround so I can speak from experience about it. The sensor would look something like this:
- platform: mqtt
name: "last security sensor"
state_topic: "home/last_sensor"
The automation I posted above would have the following action:
action:
service: mqtt.publish
data_template:
topic: 'home/last_sensor'
payload: '{{ trigger.to_state.attributes.friendly_name }}'
retain: true