#Action to update entity based on a time attribute

1 messages · Page 1 of 1 (latest)

vocal cargo
#

I have a serial integration where many different template sensors are set.
Here I have PressureID set to a value and PressureIDTS set to the date/time timestamp the PressureID was set.
I want to set the PressureID to unknown if was not seen in the serial port within the last minute. Here is the code I tried but it does not work. Maybe there is any easier way to do this within the action bit I based it on an example I saw.
´´´

  • id: '1686066013547'
    alias: Pressure Valid
    description: ''
    trigger:
    • platform: time_pattern
      minutes: /1
      condition: []
      action:
      • service: template
        data_template:
        entity_id: sensor.PressureID
        value_template: >
        {% set last_updated = state_attr('sensor.PressureIDTS', 'last_updated') %}
        {% set time_diff = (as_timestamp(now()) - as_timestamp(last_updated)) / 60 %}
        {% if time_diff > 1 %}
        unknown
        {% else %}
        {{ states('sensor.PressureID') }}
        {% endif %}
        ´´´
tacit scroll
#

You can't override a sensor value with an automation.

#

You would need to create a new template sensor, I think with an availability template to force it to unknown if a condition is not met.

vocal cargo
#

I started down that track but I could not figure out a condition that would actually work. I will try again.

vocal cargo
tacit scroll
#

No it is not, it is calling a service to request to change the brightness. There's a difference between calling a service and just trying to stomp on the value of a sensor.

vocal cargo
#

Ok. Understood. Thanks.

tacit scroll
vocal cargo
#

I have and no one has responded

tacit scroll
#

Well I guess that's how it goes sometimes. If you let some time pass then maybe try again.