Explaining "polling_frequency" Sensor

I saw the following answer in another topic.

I wanted to take a crack at understanding how it work:

  • Both to check my understanding is correct.
  • and to explain to others.

So, here goes:

  sensor:
  - name: Polling Frequency
    unique_id: 6b23d9b4-367f-4b05-9a4f-56218e8d8d3f
    device_class: timestamp

This is creating a “sensor” it’s not a binary sensor, since that would only support on/off. Instead its a “timestamp” sensor, so the result of the sensor is always a time (timestamp).

Since the sensor has a triggers block, the sensors value is not updated unless a trigger fires. The first trigger is:

  - trigger: state
    entity_id: ... # Whatever you want to use to turn on/off the polling.

Hence, if the state of a device (lets say an IR sensor changes) it will trigger.

Then the conditions block will execute.

  conditions:
  - condition: state
    entity_id: ... # whatever you need to make sure is on
    state: 'on'

So we could list the same IR sensor such that the “update” will only continue if the IR sensor is still detecting presence.

If the update proceeds the state (the result of this sensor - which is a time) is set to 10 seconds in the future:

    state: "{{ now() + timedelta(seconds=10) }}"

So 10 seconds in the future the other trigger condition will fire:

  - trigger: time
    at: sensor.polling_frequency

Assuming the condition is still true (the IR sensor is still detecting presence) the cycle will repeat.


Firstly, is my understanding correct?

Secondly there is one weird situation:

  • Say the sensor is running (the IR sensor is detecting presence)
  • The state is updating every 10 seconds (per design).
  • Then the IR sensor clears.
  • There is one “final” update when the final time occurs.
  • This appears to update the state - even though the condition is now false.

Why does this final state change occur - I would think the the condition being false should prevent that?