Turn on lights based on lux

I am a bit confused about my automation.
My automation should turn on some lights if the light is on in the living room and if the lux is under a given value. However, when value states is reached nothing happens.

When I click run automation it runs as it should, but it does not fire automatically.
image

Automation looks like this:

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    above: 90
    below: 80
  condition:
      condition: numeric_state
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_7
      above: 90
      below: 80
  action:
    - service: homeassistant.turn_on
      entity_id:
        - switch.fibaro_system_blomsterlampe
        - switch.fibaro_system_fgwpe_f_wall_plug_gen5_switch_3
    - service: light.turn_on
      entity_id:
        - light.le_klint_stalampe
        - light.trapp_2
      data:
       brightness: 140

In advance thank you for looking into this for me!

According to the documentation for a Numeric State Trigger:

Listing above and below together means the numeric_state has to be between the two values.

You have specified:

      above: 90
      below: 80

There is no value that meets that requirement.

This would work:

      above: 80
      below: 90

You’ve got your numeric_state wrong.
From the docs:

Listing above and below together means the numeric_state has to be between the two values.

EDIT: @123 beat me too it

I changed the values, but it still does not work.

Did you change the values in the trigger and the condition?

Yes, it looks like this now:

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    above: 80
    below: 90
  condition:
      condition: numeric_state
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_7
      above: 80
      below: 90
  action:
    - service: homeassistant.turn_on
      entity_id:
        - switch.fibaro_system_blomsterlampe
        - switch.fibaro_system_fgwpe_f_wall_plug_gen5_switch_3
    - service: light.turn_on
      entity_id:
        - light.le_klint_stalampe
        - light.trapp_2
      data:
       brightness: 140

I don’t think the condition is correct.

A light’s state is either on or off. It’s brightness attribute contains the current level of brightness.

Hold on I can see something not correct. It should not sate the above or below on entity_id: light.fibaro_system_fgd212_dimmer_2_level_7 this should only state if on.

Precisely.

Perhaps what you want is this:

  condition:
    condition: state
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_7
    state: 'on'

EDIT
Corrected indenting.

Yes, that is what I did now. Still no luck.
So confusing!

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    above: 80
    below: 90
  condition:
      condition: state
      entity_id: light.fibaro_system_fgd212_dimmer_2_level_7
      state: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id:
        - switch.fibaro_system_blomsterlampe
        - switch.fibaro_system_fgwpe_f_wall_plug_gen5_switch_3
    - service: light.turn_on
      entity_id:
        - light.le_klint_stalampe
        - light.trapp_2
      data:
       brightness: 140

The indenting for the condition is incorrect. Remove two spaces from the beginning of the 3 lines below condition:

(see my previous post which has been corrected).


This should work:

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    above: 80
    below: 90
  condition:
    condition: state
    entity_id: light.fibaro_system_fgd212_dimmer_2_level_7
    state: 'on'
  action:
    - service: homeassistant.turn_on
      entity_id:
        - switch.fibaro_system_blomsterlampe
        - switch.fibaro_system_fgwpe_f_wall_plug_gen5_switch_3
    - service: light.turn_on
      data: 
        entity_id:
          - light.le_klint_stalampe
          - light.trapp_2
        brightness: 140

You’ll notice I also modified the data section.

Thanks! But it sill does not want to fire.
I am just looking for it to turn on lights once it hits a lux under 90 ish. So in order to see if the automation is working or not I cover the sensor. But this automation remains still.

Try it without the condition:

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    above: 80
    below: 90
  action:
    - service: homeassistant.turn_on
      entity_id:
        - switch.fibaro_system_blomsterlampe
        - switch.fibaro_system_fgwpe_f_wall_plug_gen5_switch_3
    - service: light.turn_on
      data: 
        entity_id:
          - light.le_klint_stalampe
          - light.trapp_2
        brightness: 140

While you are covering the light sensor with your hand, look at the States page and check if the sensor’s state is within the range of 80 and 90.

Well if I cover it, it will drop lower than 80. Maybe I should remove above and only use below? The lights should turn on when the lux turns 80 or lower.

You’ve defined a narrow range of lux level (between 80 and 90) thereby making it challenging to test the automation. I agree you should simply set it to below: 80. It will make it easier to test the automation’s triggering.

That did the trick! Thanks a lot for your time and that you looked into this for me @123

You’re welcome!

I’ll post the working version here so others with a similar requirement can find it:

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    below: 80
  action:
    - service: homeassistant.turn_on
      entity_id:
        - switch.fibaro_system_blomsterlampe
        - switch.fibaro_system_fgwpe_f_wall_plug_gen5_switch_3
    - service: light.turn_on
      data: 
        entity_id:
          - light.le_klint_stalampe
          - light.trapp_2
        brightness: 140
1 Like

FYI, my front porch and garage lanterns are set to turn on when daylight luminance falls below 40 lux for at least 3 minutes. Adding the “for:” qualifier insures light has constantly and stably diminished. Without it, there was occasional ‘bounce’ in the values and lights would occasionally turn on and off too much.

- alias: Skru på Blomsterlampe, Leimu og stue hvis det er under x antall lux
  trigger:
    platform: numeric_state
    entity_id: sensor.fibaro_system_fgms001_zw5_motion_sensor_luminance
    below: 80
    for:
      minutes: 3

Thanks :smiley:.
Great suggestion, will add it straight away.

Is the light sensor anywhere near the lights that this automation turns on?

In other words, is its measurement influenced by the brightness of the lights that get turned on?

If so, you may encounter this undesirable behavior:

  • Light decreases below 80.
  • Automation is triggered and turns on lights.
  • Light increases above 80.
  • Someone turns off a few of the lights manually.
  • Light decreases below 80.
  • Automation is triggered and turns on the lights that were just turned off.