Help with lux automation

Hi

I’m trying to make a simple automation to turn on a couple of lights based on lux. However, sometimes it triggers but nothing happens and sometime it doesn’t even trigger. I have similar automations with three different brightness settings and time conditions, lower brightness towards the evening.
I’ve used the webgui to configure it.
I got other lightbased automation that works just fine. For exemple “Turn off light when alarm is armed”.

Here’s my code from automation.yaml:

- id: '1574243431814'
  alias: 'Belysning: förmiddag'
  description: Full belysning övervåningen dagtid
  trigger:
  - below: '500'
    entity_id: sensor.aeon_labs_zw100_multisensor_6_luminance
    platform: numeric_state
  condition:
  - after: '12:00'
    before: '15:59'
    condition: time
  - condition: state
    entity_id: alarm_control_panel.skonertgrand_alarm
    state: disarmed
  action:
  - data:
      brightness_pct: 85
      entity_id: light.hallen
    service: light.turn_on
  - data:
      brightness_pct: 85
      entity_id: light.koket
    service: light.turn_on
  - data:
      brightness_pct: 95
      entity_id: light.vardagsrummet
    service: light.turn_on

The other two looks just the same apart from other brightness_pct, time condition and lux value.
Thanks for any help.

Do you get an error in the logs? Is this how it came out of the GUI or did you change anything?

I’m not sure on this but I think you need to split up this condition into two conditions:

From this:

- after: '12:00'
  before: '15:59'
  condition: time

To this:

- after: '12:00'
  condition: time
- before: '15:59'
  condition: time

Also remove the single quotes around 500, could be that it gets interpreted as a string if you put it in quotes.

Yes this is how it comes out of the GUI.
I’ll give it a shot to split the time condtion into two.
The issue that I’m having though is that it does tigger but doesn’t perform the action. As far as I can see there isn’t anything wrong with the action.
Since postning I’ve also added an input_boolean so each automation only triggers once per day.

Then I’m almost sure that you need to split the condition into two conditons.

You don’t need to split the time condition. See here. I use automations with a time condition like the one in the example at that page with no issues. The time condition OP has will return true if the time is between 12:00 and 15:59.

The numeric state trigger requires the sensor to cross the threshold that you have defined for it to trigger. In this case, the sensor needs to be above 500 and then go below 500 for it to trigger. If it’s already below that threshold, it won’t trigger (otherwise it would trigger constantly). The action does indeed look ok, so I’m not sure why it wouldn’t carry out those actions when the automation is fired.

1 Like

Damn, so then I’m confused because it looks ok to me as well.

Are you saying you see “automation x has been triggered” in your logbook? If so, do you see any errors in your log when this happens?

In that case, if the conditions are met, I’m assuming the sensor is already below 500 in which case the automation won’t trigger.

I just checked my automations and the evening-light automation was triggered 20:33.
At the same time I got this error in my logs:
Error reporting state - 5: Requested entity was not found.
20:33 components/cloud/google_config.py (WARNING) - message first occurred at 17:04 and shows up 3 times.

Here is how the evening automation looks now.

Automations.yaml

  alias: 'Belysning: kväll'
  description: Mycket dämpad belysning övervåningen kvällstid
  trigger:
  - below: '100'
    entity_id: sensor.aeon_labs_zw100_multisensor_6_luminance
    platform: numeric_state
  condition:
  - condition: state
    entity_id: alarm_control_panel.skonertgrand_alarm
    state: disarmed
  - condition: state
    entity_id: input_boolean.reset_automation_evening
    state: 'on'
  - after: '19:30'
    condition: time
  - before: '22:59'
    condition: time
  action:
  - data:
      brightness_pct: 10
      entity_id: light.hallen
    service: light.turn_on
  - data:
      brightness_pct: 10
      entity_id: light.koket
    service: light.turn_on
  - data:
      brightness_pct: 35
      entity_id: light.vardagsrummet
    service: light.turn_on
  - data:
      entity_id: input_boolean.reset_automation_evening
    service: input_boolean.turn_off

Okay, the sensor never went above 500 lux today, peaked at 331. So it’s understandable that the daytime automation never fired then.

I’ll let the whole thing run for a day and see if it triggers as it should. Thanks for all the help. I’ll get back with the results tomorrow.

I let it run and found that all three booleans (for the three different automations) were set to OFF at the same time, 12:49 PM. However when I turned them on and then ran:

automation.reload

it fired the first automation but when time came to trigger the next one it never did so I reloaded the automation again and then it was triggered. This is strange. I might as well remove all and redo them, might get lucky :smile:

I have same issue. My automation worked for 2 days, but not working after that.
I have a binary_sensor to set a threshold value and automated that to turn on/off that sensor.
binary_sensor.yaml

  - platform: threshold
    name: "Low LUX"
    entity_id: sensor.outdoor_illuminance_sensor
    lower: 45

automations.yaml

- id: '1569856790157'
  alias: Evening Lights
  trigger:
  - entity_id: binary_sensor.low_lux
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: '17:30:00'
    before: 06:00:00
    condition: time
  action:
  - alias: ''
    data: {}
    entity_id: switch.front_door_light
    service: switch.turn_on

I have another automation to turn off the devices at morning

- id: '1569856841369'
  alias: Morning Lights
  trigger:
  - entity_id: binary_sensor.low_lux
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - after: 06:00:00
    before: '17:30:00'
    condition: time
  action:
  - alias: ''
    data: {}
    entity_id: light.all_bulbs
    service: light.turn_off
  - data: {}
    entity_id: switch.front_door_light
    service: switch.turn_off

But, morning automation apparently triggered outside the time frame specified in automation.
image

If I trigger manually, these automations works without any issues.

Do I need to change anything?

What do you mean it triggered outside the time interval set in the automation? 4:45 PM is 16:45, which is before 17:30 and after 06:00

my bad, It’s with in time. But it’s not triggering at starting time and triggered at random time. Any way to trigger it at particular time?

What you probably want is two triggers, one at 6:00 and another one when the binary sensor goes to off. Add conditions as needed.

Checked a full day. Morning trigger worked, but evening trigger not working.

Your time condition for the evening automation passes midnight, it will not work.

Let’s say it’s 03:00:00, this value is before 06:00:00 but it’s not after 17:30:00.

You need to create two separate conditions and make them OR conditions.

One condition after 17:30:00 and one condition before 06:00:00.

Thanks for the reply. I did split the time, one is after 17:30:00 and one is before 06:00:00. Still not working.
Shall I try placing the before timing first and then after time?
If changing day is the issue, shall I created 2 or 4 conditions? Like 17:30:00 to 23:59:59 and one from 00:00:00 to 06:00:00? Or split them also?

Can you please show the code? Did you also change the conditions to OR conditions?

The order of the conditions doesn’t matter here.

The condition should be like this:

condition: 
  condition: or
  conditions:
    - condition: time
      after: "17:30:00"
    - condition: time
      before: "06:00:00"
1 Like

I’m using both time condition,
Now changed time one is from 17:30:00 to 23:59:59 and one is from 00:00:00 to 06:00:00.

- id: '1569856790157'
  alias: Evening Lights
  trigger:
  - entity_id: binary_sensor.low_lux
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: '17:30:00'
    before: '23:59:59'
    condition: time
  - after: 00:00:00
    before: 06:00:00
    condition: time
  action:
  - alias: ''
    data: {}
    entity_id: switch.front_door_light
    service: switch.turn_on

I’m using automation editor to write code.
Waiting for tomorrow evening to trigger automatically. I’ll try your code and let you know.