Hello.
My task is to receive sensor data only when the transient process is over.
Those. there is a sensor sensor.raw_data and the task is to write only data to the sensor data, after a certain time.
- alias: set_sensor
trigger:
- platform: state
entity_id:
- sensor.raw_data
condition:
condition: state
entity_id: sensor.device_state
state: 'on'
for:
minutes: 20
action:
- service: set.sensor
entity_id: sensor.data
data:
{{ states.sensor.raw_data.state }}
tom_l
October 27, 2020, 8:28am
2
Evgeny_Polupanov:
service: set.sensor
There isn’t a service for this.
You will have to create a template sensor.
First search, after ask:
We must make python script (thanks for rodpayne )
set_sensor_state.py:
inputEntity = data.get('entity_id')
if inputEntity is None:
logger.warning("===== entity_id is required if you want to set something.")
else:
inputStateObject = hass.states.get(inputEntity)
inputState = inputStateObject.state
inputAttributesObject = inputStateObject.attributes.copy()
for item in data:
newAttribute = data.get(item)
logger.debug("===== item = {0}; value = {1}".format(item,newAttribute))
if item == 'entity_id':
continue # already handled
elif item == 'state':
inputState = newAttribute
else:
inputAttributesObject[item] = newAttribute
hass.states.set(inputEntity, inputState, inputAttributesObject)
And action for set sensor
action:
- service: python_script.set_sensor_state
entity_id: sensor.data
data:
{{ states.sensor.raw_data.state }}
Are you aware that this sensor will be lost when you restart HA? And only be available again, once you use the python script again.
it’s not a problem in my way