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.
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.
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.
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.
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).