I’m trying to set up a simple automation that will turn on some lights when the ambient light is low, using the sensor illuminance entity as a trigger. I searched the forum and found an article explaining how to do it, using “Numeric state” as the trigger (see here: Luminance Lux sensor - with delay).
My automation doesn’t seem complex at all, but it just doesn’t work. I can confirm the sensor is working (see screenshot #3) and I can trigger the lights manually. Additionally, I can confirm the lux level was below the entered threshold (400 here) at the time of testing. I’m wondering if anyone can spot a reason why this automation is not working - I’ve included screenshots of the GUI, as well as, the embedded code.
- id: '1648967710992'
alias: Morning - Ambient Light Low - Inside Lights - ON
description: This is slightly different than the "Daytime - Ambient Light Low -
Inside Lights - On" piston. This one looks for low ambient light at the time the
kids are getting ready in the mornings (6:40 - 7:00) during winter months. If
the light is low during that time, the inside lights are switched on. During the
winter months, sunrise happens later - like after 7:00AM - the lights need to
be on, while kids are getting ready for school 7-8AM.
trigger:
- platform: numeric_state
entity_id: sensor.dining_room_trisensor_illuminance
attribute: ''
below: '400'
condition: []
action:
- type: turn_on
device_id: 15acccbc7a179603099aa33b2e6996f6
entity_id: switch.dining_room_painting_lights
domain: switch
- type: turn_on
device_id: 0baa2e8c442c2e535fb26e1a8aab7de2
entity_id: switch.living_room_lamp_socket_1
domain: switch
mode: single
If the value was already below the threshold, the Numeric State Trigger won’t trigger. The value will first have to increase above the threshold, then at the moment it decreases and crosses below the threshold the Numeric State Trigger will trigger.
I don’t have much experience using “trace” to troubleshoot. So, I’m not sure what I’d be looking for. I have included screenshots of all 4 tabs in the trace page, and am embedding the code. For testing purposes, I did increase the threshold lux to 40,000 because it’s daytime now, and the illuminance is currently around 22k.
One thing I did note as somewhat odd, is that in the last line of the code (embedded here), the mode is listed as “queued”, but I have it set to “single”. I don’t know if that is significant.
id: '1648967710992'
alias: Morning - Ambient Light Low - Inside Lights - ON
description: >-
This is slightly different than the "Daytime - Ambient Light Low - Inside
Lights - On" piston. This one looks for low ambient light at the time the kids
are getting ready in the mornings (6:40 - 7:00) during winter months. If the
light is low during that time, the inside lights are switched on. During the
winter months, sunrise happens later - like after 7:00AM - the lights need to
be on, while kids are getting ready for school 7-8AM.
trigger:
- platform: numeric_state
entity_id: sensor.dining_room_trisensor_illuminance
attribute: ''
below: '4000'
condition: []
action:
- type: turn_on
device_id: 15acccbc7a179603099aa33b2e6996f6
entity_id: switch.dining_room_painting_lights
domain: switch
- type: turn_on
device_id: 0baa2e8c442c2e535fb26e1a8aab7de2
entity_id: switch.living_room_lamp_socket_1
domain: switch
mode: queued
So if I see the data…then all has been turned ‘on’ and you say nothing is on?
And indeed, I would not expect queued…seems there are some other still running
You can test the individual steps in the automation too…
The trace you posted is when you triggered the automation manually which is of limited use. Manually triggering an automation skips its trigger and merely exercises the action.
In this case, the automation’s mode value has no bearing on the issue.
This is just another case of a misunderstanding of how the Numeric State Trigger works.
I can confirm that when I run the actions for each device they turn on appropriately. I could just remove them for now and call a service to notify me with a text. But, I don’t think that’s going to help much. I really think the problem is with the trigger, rather than the action.
Here, I’m including the code copied directly out of my automation.yaml file. The code included in the last message was from the “show trace” part of the GUI. There is a difference in the lux threshold and the mode. From the automation.yaml, the lux threshold I’ve set is 60k, but in the show trace part it’s 4k. And, the mode is correctly set to “single” in the automation.yaml, but it is set as “queued” in the trace code.
- id: '1648967710992'
alias: Morning - Ambient Light Low - Inside Lights - ON
description: This is slightly different than the "Daytime - Ambient Light Low -
Inside Lights - On" piston. This one looks for low ambient light at the time the
kids are getting ready in the mornings (6:40 - 7:00) during winter months. If
the light is low during that time, the inside lights are switched on. During the
winter months, sunrise happens later - like after 7:00AM - the lights need to
be on, while kids are getting ready for school 7-8AM.
trigger:
- platform: numeric_state
entity_id: sensor.dining_room_trisensor_illuminance
attribute: ''
below: '60000'
condition: []
action:
- type: turn_on
device_id: 15acccbc7a179603099aa33b2e6996f6
entity_id: switch.dining_room_painting_lights
domain: switch
- type: turn_on
device_id: 0baa2e8c442c2e535fb26e1a8aab7de2
entity_id: switch.living_room_lamp_socket_1
domain: switch
mode: single
Vingerha… sorry for the rookie question… how to I change the state of the sensor? Is that something I’m supposed to do at the sensor itself, or is it something I do in the HA interface?
You can set an entity’s value in Developer Tools > States. However, the value you set this way will only last until the actual device reports its current state (the interval depends on the device and may be as short as 15 seconds or more than a minute).
Given that this device is a light sensor, the simplest way to change its reported value is by simply shining a light on it or covering it with your hand, then wait for the new value to be reported to Home Assistant.
Well, that’s interesting. I set the illuminance state to 200, using Developer Tools, and the automation runs. Makes me wonder if the sensor just isn’t reporting frequently enough.
I currently have the threshold set to below 60,000. Additionally, I just configured the sensor to report every 20 seconds. Now, what is interesting is, when I set the following illuminance states, these are the results:
Illuminence: 399 and lower → automation triggers
Illuminence: 400 and higher → automation does not trigger
This gets me back to the “show trace” part of the code. In that part, it shows a threshold of 400. But, when I go directly to the automations.yaml code, I can confirm I have it set to 60,000.
The confusing results from the last test, where the lights turned on with a threshold of 399 or lower, were being caused by a different automation. That’s useful information too, because the illuminance trigger on that one is working perfectly, and that automation is very similarly designed. So, here’s an update on what I’ve done, and where things stand:
Disabled all other automations except this one.
Completely deleted the automation and reprogrammed from scratch with an illuminance threshold of lower than 60,000.
In Developer tools, set the illuminance state to several different test values, including 200, 399, 400, and 600. In every case, the automation never runs.
Included are GUI screenshots and embedded code. I really do appreciate all your help on this… it’s driving me absolutely nuts!
Using the method I described earlier, set the sensor’s state to a value above 60000 first then set it to a value below 60000. That should trigger the automation (it’s the crossing from a value above the threshold to a value below it that serves to trigger the automation). Let me know if it does or doesn’t.
Duh. That fixed the last of it. Gotta be smarter than the code, I guess. Thanks a ton for all the help. I think the original problem was that my Aeotec Trisensor was set to report every 60 minutes, and after I reconfigured it to report every 20 seconds, I’d already set the really high 60k illuminance threshold. Then, it just didn’t cross my mind to set values higher and lower.
As a newcomer to HA, I really, really appreciate this community. People here have been so helpful.
1 Like
Tinkerer
(aka DubhAd on GitHub)
Split this topic
20