Help with solution for preventing automation from triggering after a reboot

Hi,

Looking for some help with an automation that keeps triggering when home assistant restarts

id: '1637678191203'
alias: Living Room - Turn on Living Room Lights when Lux level below 450 (Home)
description: ''
trigger:
  - type: illuminance
    platform: device
    device_id: 42f6a4e79d9bb0a7307adc5cf8f1b6fd
    entity_id: 4e2ebd3a077bbc9c79e6e35a828ce5da
    domain: sensor
    below: 450
condition:
  - condition: state
    state: Home
    entity_id: sensor.hub_mode
  - condition: state
    entity_id: light.living_room_lights
    state: 'off'
  - condition: or
    conditions:
      - condition: state
        entity_id: switch.living_room_speakers
        state: 'on'
      - condition: state
        entity_id: switch.living_room_tv
        state: 'on'
      - condition: state
        entity_id: input_boolean.living_room_computer
        state: 'on'
action:
  - service: light.turn_on
    data:
      brightness_pct: 20
      transition: 1
    target:
      area_id: living_room_lights
mode: single

the automation essentially turns on lights when the lux value goes below 450 from my ecowitt weather station. it all seems to work as expected but I have 1 issue to overcome.

if the lights are off but but home assistant is rebooted the lux value changes from unavailable to the value below the trigger point (Which I think is expected) but I dont want that to happen. I only want the lights to trigger when the value goes below when the sun is going down.

I suspect as you say that in reboot HA sees the value is below 450 and triggers the automation.

I think if you replace the device trigger for a state trigger, you could prevent this. If you use a numerical state of below 450 as the trigger then the automation technically won’t trigger unless it sees the value transition from any value above 450 to any value below 450.

Add the following Template Condition to your automation. It ensures that the sensor’s previous value of lux level was numeric (i.e. not unavailable).

condition:
  - condition: template 
    value_template: "{{ trigger.from_state.state | is_number }}"
  - condition: state
    state: Home
  - condition: state
    entity_id: light.living_room_lights
    state: 'off'
... etc ...

[/quote]

condition:
  - condition: template
    value_template: >-
      {{ ((as_timestamp(now()) -
      as_timestamp(states.sensor.hass_uptime.last_changed)) >= 5) }}
1 Like

I changed to a state trigger but got the same issue!

Thanks, this solved the issue I was having!

1 Like