You can actually test it by executing the automation twice in succession. It should not turn on the lights in the second time. Don’t worry about the trigger, you may get errors about that. But you can at least test the automation w/ the lights.
that would be empty, just as it would be when time_pattern, or any other non entity triggering trigger would be triggering the automation.
Should have been more precise and have said:
could this not simply be replaced by {{'time' if trigger.now is defined else trigger.entity_id}}
Coming to think of that, since there are many other triggers possible (events, homeassistant, etc etc) , maybe something like:
{{trigger.entity_id if trigger.entity_id is defined else trigger.platform}}
would catch all?
I guess the short answer is “Sure, why not.” and the long answer is 'Sure, but that’s not what the original example wanted to achieve."
mm, I’m not clear on the difference between the 2, other than my suggestion being shorter, and agnostic to the state, which makes it more robust.
which would make a fine answer to ‘why’ imho
Use whatever you feel is best.
While this is an old thread I’m faced with the same question as @argykaraz. However my situation is different.
Here’s what happens:
For a few weeks all my lights in the house turn on at (what appears to be) random times. Even though I turn off all lights after this happens they come back on at times.
I should add that I have only recently gotten into automations and writing scripts and it’s obvious that I messed up somewhere because I probably attempted too much without enough testing. I had a look at the logbook and it shows me the lights come on. But as commented earlier in this thread the logbook doesn’t tell me what triggered a service.
We all have the HA companion app installed and at times it appears turning on the lights may be connected to the proximity relative to the house but without confirming this I can’t say for sure. I also had a look at the time stamp of my automations and last run timestamps don’t correspond with the lights turning on.
Is there a way to make use of the events bus (Events - Home Assistant)? Can I listen to events? What events to listen to and what’s the syntax in the events section under developer tools? As an example could we find out what triggered the service light.turn_on
with the events section?
Sorry for the long post but there’s a level of frustration for not knowing how to troubleshoot this and it doesn’t do well with the WAF
Do you have adaptive lighting integration or is your system connected to alexa?
Also, this post is old. Currently, in HA, you can trace any automation and see what cause it to trigger.
No, I don’t have the adaptive lighting integration or Alexa in my house.
Furthermore there’s no current automation with all lights in scope. Also checking the last triggered timestamp for all automations doesn’t align with the time the lights turn on.
If you refer to the Trace function in automations I’m aware of that but given there’s no tally re timing I’m not sure how I could apply that.
If there was a way to find out who calls the service light.turn_on I might be able to go back to the source. Could I use events in developer tools for this? What do I listen for?
The traces show you who calls the service, in the logbook tab. By default, 5 traces are saved. You can increase that amount per automation.
No clue what you’re even saying here.
The only way to debug automations is to use the traces.
You can subscribe to call_service events, but that won’t show you past events. Plus, the context shown in those events will be the “under the hood” values, you’ll have to translate the context into automation’s or people using a template.
HA by default doesn’t create anything with “all lights” either. So if you created something with “all lights”, look at that first.
“no tally re timing” refers to the fact that there is no last run time stamp for any of the automations that corresponds with the time the lights turn on which makes me wonder what else could trigger this.
Is there any way other than automations (and the developer tools of course) to call light.turn_on?
Then it’s unlikely that it’s coming from an automation.
Other integrations can do this. But you’ll see the context in the logbook. If you don’t see context in the logbook, that means the turn on event is coming from outside HA.
example of a logbook event without context:
exmplae of a logbook event pointing to an automation or script:
Example of logbook event by a person (in my case I have a user named alexa)
Ok thanks. That gives me more context to troubleshoot as I haven’t really dived into scripts so far
Any updates on this mate, I’m having similar issues?
I am having this happen all the time in random sequences. How do you track down what automation or script is turning the light on? I don’t have any scripts and the few automations I have do not include any of the lights that are turning on…
UCL 4 turned on triggered by service Light: Turn on
14:01:16 - 2 hours ago