Variables problem on a trigger in an automation

Hi, Im doing an automation where a trigger of light should be above 500 lux to kick off the automation.
I get that to work with no problem when I in the automation use -above: 500 hardcoded, see example below. But as soon as I try to use my helper i created, and exchange 500 to the name of the helper I only get errors when trying to save. I used all formats I could find in different forums for variables but I don’t crack this. I get a constant float error in most cases.

Can anyone educate me on the correct template to use for exchanging 500 to my variable, including correct parentheses and spaces needed. Or s this not possible in a trigger……
///////
alias: egen ljus sensor - test
description: “”
trigger:

  • type: illuminance
    platform: device
    device_id: c9d4c601cf63b4f64699c02c2ba8a320
    entity_id: de5eeb7683c0d61519a16e988039e1a9
    domain: sensor
    above: 500
    for:
    hours: 0
    minutes: 0
    seconds: 10
    enabled: true
    \\\\\

You can’t use templates with device ids - try a state trigger with an entity id.

1 Like

Thanks! I tried to change so I get the entity ID instead, the same Philips light sensor. I get that but I hav no luck in making this trigger work. In the automation it ask for For and TO values instead of “Above”. Maybe I don’t understand the settings here….
I have tried all combination of From and To, like 500, <500, >500 but no luck to kick of the automation.

alias: egen ljus sensor tillstånd - test
description: “”
trigger:

  • platform: state
    entity_id:
    • sensor.hue_motion_sensor_2_light_level
      for:
      hours: 0
      minutes: 0
      seconds: 10
      to: “>500”

Sorry, my fault. I should have said numeric state - that will give you above and below options.

In the future, instead of trying all combinations, I recommend you check the trigger’s documentation. For example, the documentation for State Trigger doesn’t mention that symbols, like >, can be used in a value nor does it show an example with it. Generally speaking, when something is not explicitly mentioned then it’s usually unsupported.

The Numeric State Trigger also doesn’t support the use of symbols. However it does support above and below instead of to and from.

For example, the following Numeric State Trigger will trigger at the moment when the sensor’s value increases and crosses the threshold of 500 and remains above 500 for at least 10 seconds.

  - platform: numeric_state
    entity_id: sensor.hue_motion_sensor_2_light_level
    above: 500
    for:
      seconds: 10

It’s important to keep in mind that a Numeric State Trigger is triggered only when the entity’s value crosses the threshold value. If the entity’s value is already above the threshold, it will not trigger.

The documentation also explains you can use an Input Number entity to supply the threshold value.

  - platform: numeric_state
    entity_id: sensor.hue_motion_sensor_2_light_level
    above: input_number.whatever
    for:
      seconds: 10

1 Like

@123 , great lesson given!! I love it. That was what I of course should have found and read by myself. I have used HA quite a while but recently tried to leave Nod-Red to use HA Automations instead. Much more to learn, and this was a really good practice. The logic as asked for above is now working and Im going to add Sun elevation/azimuth as Conditions. Great help from both you and @Stiltjack
Highly appreciated!