Yesterday I tried to make my first automation that supposedly it turns un my light when a light sensor detects that is dark, it didn’t work so I have been tinkering with it trying to make it work but nothing.
here is the YAML configuration:
alias: autolights
description: Turn the lights on when dark
trigger:
- type: value
platform: device
device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
entity_id: sensor.light
domain: sensor
below: 100
for:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
condition:
- condition: and
conditions:
- condition: state
entity_id: device_tracker.iphone
state: home
attribute: device_tracker
- condition: device
type: is_off
device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
entity_id: switch.xxxxxxxxxxxxxxxxxxxx_x
domain: switch
- condition: and
conditions:
- condition: time
before: '23:00'
after: '12:00'
weekday:
- mon
- tue
- wed
- thu
- fri
- sat
- sun
action:
- type: turn_on
device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
entity_id: switch.xxxxxxxxxxxxxxxxxxxx_x
domain: switch
- type: turn_on
device_id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
entity_id: switch.xxxxxxxxxxxxxxxxxxxx
domain: switch
mode: restart
I am using a Smart Life light and a BH1750 sensor with ESPHome
there are a few troubleshooting steps you can take:
you can use the new automation debugger that is found in the “automations” section of the configuration menu. click the little timer icon beside the automation. It should give you atrace and tell you where it failed.
you can manually trigger the automation in the services section of developers tools. first trigger it with the “skip conditions” box unchecked and if it works then check the box and trigger it again. if it fails with skipping conditions then the problem is in the action. If it fails only after not skipping conditions then the failure is in the conditions. If it works under both conditions then the problem is with the trigger.
When you manually execute an automation, it skips the automation’s trigger and condition; it only executes the action.
Your test confirms the problem lies either in the trigger or the condition. I believe the problem is in the condition, specifically, this line which should be removed:
I tried the automation debugger but I didn’t understand what’s happening, it shows that it fails on the condition but I don’t know why
An when I trigger it from the services section of developers tool, it turns on the light even if the sensor gives a value above 100 or if it is 9:00 am
You overlooked to mention that previously. All we know is what you tell us and all you have told us is that the light turns on when you trigger the automation manually. That simply means the action works and the problem is with either the trigger or the condition.
For testing purposes, how are you activating the automation’s trigger? You must make the light sensor’s value change from a value higher than 100 to a value lower than 100, for at least a minute, for it to trigger. If the value is currently 90, making it decrease will not trigger the automation. To trigger, it must start from a value above 100 then decrease below 100.
If you say the sensor’s value is initially between 6K and 3K and covering it with tape makes it go below 100 (and stay that way for at least a minute), then that should be sufficient to trigger the automation. If the action isn’t executed then it’s because the condition (of the three conditions) prevents it.
Here is the equivalent of your three conditions. You can replace what you currently have with this: