Compact these 2 small automations using numeric_state?

though very basic, I must confess I am struggling to find a way how to compress this into 1 automation using a trigger.below and trigger.above on the -3.5…

can we do that at all since the trigger cant be both below and above? or should I write it verbosely

    trigger:
      - platform: numeric_state
        entity_id: sun.sun
        attribute: elevation
        below: -3.5
      - platform: numeric_state
        entity_id: sun.sun
        attribute: elevation
        below: -3.5
  - alias: Sun elevation sets outside motion sensors
    id: Sun elevation sets outside motion sensors
    trigger:
      platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: -3.5
    action:
      service: homeassistant.turn_on
      entity_id: group.philips_buiten_motion_sensor_switches

  - alias: Outside motion sensors off when light outside
    id: Outside motion sensors off when light outside
    trigger:
      platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: -3.5
    action:
      service: homeassistant.turn_off
      entity_id: group.philips_buiten_motion_sensor_switches

goal is obvious: turn_on when below -3.5, turn_off when above -3.5 … so how to write the service template

 service: homeassistant.turn_{{'off' if trigger.above else 'on'))

please have a look?
thanks

trigger.above only resolves to the above: value that you provided, not that the trigger occurred because the value was above your threshold. You need to do a numeric comparison with trigger.to_state.state|float > trigger.above for that.

As to how to simplify the automation, I would just use a state trigger to trigger on every state change:

  - alias: Outside motion sensors off when light outside
    id: Outside motion sensors off when light outside
    trigger:
      platform: state
      entity_id: sun.sun
      attribute: elevation
    action:
      service: homeassistant.turn_{{'off' if trigger.to_state.state|float > -3.5 else 'on'))
      entity_id: group.philips_buiten_motion_sensor_switches
1 Like

ok, thanks.
in test case, I would be even more compact using a state trigger on elevation per se and …

you beat me to it… :wink: