Turn light on at a Lux Value

Hey Guys,

need some help. Hope I’m correct here. :slight_smile:

I have an automation that should turn on the lights in our living room.
Wether 0,5 hour before sunset (works fine) or the light is below 2000 Lux (doesn’t work).

I don’t know if I’m doing something wrong. Thought that I just have to create an attribute “lx” and set the value below 2000. But this was to easy Im afraid.
May you can find an mistake. :slight_smile:

alias: Stube - Licht an bei Dunkelheit
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.stube_bewegungsmelder_beleuchtungsstarke
    attribute: lx
    below: 2000
  - trigger: sun
    event: sunset
    offset: "-00:30:00"
conditions: []
actions:
  - action: light.turn_on
    metadata: {}
    data:
      brightness_pct: 100
    target:
      entity_id:
        - light.anker_schalter
        - light.signify_netherlands_b_v_lom001_schalter
        - light.sideboard_schalter
        - light.signify_netherlands_b_v_lom007_schalter
        - light.bankerlampe_leuchte
        - light.sofa
        - light.schreibtisch
        - light.stube_vitrine_schalter
mode: single

Have a great evening. 

Do you need an attribute? My automation works fine w/o defining an attribute.

description: ""
mode: single
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.yard_lux
    below: 300
conditions: []
actions: []

Hi Bob :slight_smile:

Thanks for your reply.
Hm … dk. Didn’t try it yet without.
I’m new to all this stuff.
I’ll try it without and let you know. Might take a few. Already dark here. :wink:

Greetings from Hamburg

Armin

I’m not sure what you mean by that. You don’t “create” attributes unless you’re defining a template sensor. If you did that, how did you do it?

A sensor entity like sensor.stube_bewegungsmelder_beleuchtungsstarke, and basically every other entity in Home Assistant, has a state, and zero or more attributes. The state is usually the thing the sensor is supposed to be reporting (like an illuminance value). Attributes are often meta-information, although for more complex sensors it’s sometimes difficult to explain why one kind of value is chosen as the state and others are the attributes. But the HA architecture requires every entity to have a state, and the attributes are optional, so you have to have a state.

You can see the state of any entity, and then all of its attributes (if it has them) in Developer Tools → States. So you can go there, find the sensor, and see whether the lux value is in the state or in an attribute, whether called lx or something else.

1 Like

Hey Dominic,

thanks for explanation.
I didn’t define a template sensor. Wouldn’t know how to. :slight_smile:

Here is what I found in the States Tab.


Is it that what we are looking for?

Got it. So you should definitely delete the attribute line. What you’re pointing to in the screenshot is the unit of measurement (lux), and it’s stored in an attribute called unit_of_measurement. That attribute of the sensor just tells you what units the state of the sensor is provided in.

For your automation, it’s the state you care about (1752 lux in your screenshot). By deleting the attribute line in your code, you’ll be telling Home Assistant that you want it to look at the state of the sensor, rather than an attribute called “lx” (which doesn’t exist, which doesn’t make sense with a numeric_state trigger, … and which is never going to change for this sensor).

2 Likes

Thank you very much. :slight_smile:

Have a good night.

Works well. Thanks again.

But now I ran into another thing.
What if the lux is over 2000 again?
Then the lights should turn off or the sun rises.

I tried to test a blue-print for this but it was toooooo much information for me. :smiley:

Just create a second automation that triggers on sunrise or at above 2000–and calls light.turn_off.

1 Like

Did it like this now. :slight_smile:

alias: Stube - Licht an bei Dunkelheit
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.stube_bewegungsmelder_beleuchtungsstarke
    below: 2000
    id: dunkel
  - trigger: sun
    event: sunset
    offset: "-00:30:00"
    id: Sonnenuntergang
  - trigger: sun
    event: sunrise
    offset: "-00:30:00"
    id: Sonnenaufgang
  - trigger: numeric_state
    entity_id:
      - sensor.stube_bewegungsmelder_beleuchtungsstarke
    above: 2000
    id: hell
conditions:
  - condition: time
    after: "08:00:00"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
actions:
  - if:
      - condition: trigger
        id:
          - Sonnenuntergang
          - dunkel
    then:
      - action: light.turn_on
        metadata: {}
        data:
          brightness_pct: 100
          kelvin: 6500
        target:
          entity_id:
            - light.sofa
            - light.signify_netherlands_b_v_lom001_schalter
            - light.sideboard_schalter
            - light.signify_netherlands_b_v_lom007_schalter
            - light.stube_vitrine_schalter
            - light.bankerlampe_leuchte
            - light.schreibtisch
            - light.anker_schalter
    alias: Licht an
  - if:
      - condition: trigger
        id:
          - Sonnenaufgang
          - hell
    then:
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id:
            - light.sofa
            - light.signify_netherlands_b_v_lom001_schalter
            - light.sideboard_schalter
            - light.signify_netherlands_b_v_lom007_schalter
            - light.stube_vitrine_schalter
            - light.bankerlampe_leuchte
            - light.schreibtisch
            - light.anker_schalter
    alias: Licht aus
mode: single
1 Like