Why my automation with numeric state trigger didn't trigger after downtime?

My automation, which turns off smart plug after tablet battery reaches 94%, didn’t trigger when HA was started after 7 hours of downtime.

The plug was ON, so my tablet was in charging state when my server crashed. What I don’t understand, why this automation didn’t trigger when I started HA after 7 hours. Well entity state value was updated to 100%, so I suppose this should trigger it, because it’s above the last recorded value(57%)?

Here’s the automation and history graph:

alias: Samsung Tab - Stop charging at 94%
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.samsung_tab_a7_battery_level
    above: '93'
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.plug_samsung_tab
mode: single

Your sensor state has to go from below 93 to above 93 to cause the automation to trigger.

When you started Home Assistant your sensor state went from unavailable to 100. unavailable is not below 93, thus it did not trigger.

If you want it to trigger in that case you have to do this:

alias: Samsung Tab - Stop charging at 94%
description: ''
trigger:
  - platform: numeric_state
    entity_id: sensor.samsung_tab_a7_battery_level
    above: '93'
  - event: start
    platform: homeassistant
condition:
  - condition: numeric_state
    entity_id: sensor.samsung_tab_a7_battery_level
    above: 93
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.plug_samsung_tab
mode: single

Thanks for the reply.

When you started Home Assistant your sensor state went from unavailable to 100. unavailable is not below 93, thus it did not trigger.

Thought about that, but I don’t see any mark in graph that state was unavailable. Wouldn’t it show grey color(or just empty) space when state was unavailable?

image

Home assistant was off. It was unavailable.

Yeah, I get it now. I knew that HA does not restore states after restart, but I didn’t thought about that for this situation.