Event triggering tracking in logs

In 15 minutes of HA restart some switches have been turned off , I can see this in logbook. But I do not see what triggered them. for instance 3 shutters out of 7 were closed. at the same time the rest of them are still open. How can I check why those 3 switches were turned off?

Do you mean 15 minutes after a restart?

If so then it’s most likely a normal automation.
Not anything that is triggered by the restart itself.

yes. I rebooted HA and then in 10-15 min two automation jobs were triggered… Ho w to find what user triggered them? is it possible?

You don’t give us much to work with.

But yes, most of the time you can see in the history of the triggering entities which triggered.
But if you mean someone executed it manually, then no.

At the moment if an entity state change was caused by an automation the only way to see that is if you log automations and there is one nearby,

Untitled

There is an update coming soon that will add the context of which automation changed the state the way a user does now.

Ok, let me explain… HA restarts at 23:47. What I do not understand is last 4 records: 2 automation which supposed to be triggered by sun angle (and each one has own angle) ; 2 shutters. Ok, it is hard to understand why but where in system log I can see related log records with user (system user) which triggered those?

You can’t in the logbook, yet. As I said it is coming soon:

Hopefully in 0.115.

If you set the logging level to debug you should be able to trace it in the system log (configuration / logs).

Don’t leave the logging level set to debug for too long. It’s very chatty and will reduce the life of an SD card if you use one. Set it back to info or warning when finished debugging.

1 Like

Yes, I understand but my automatons were not supposed to be triggered… they are not set to be triggered by time but absolutely other conditions whch cannot be met at that moment of events I am talking about. And what is more, the conditions for both authorizations are different! cannot be triggered at the same time.

- alias: Close all shutters at dusk-dark -6 degrees
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') }}'
    below: -5
  action:
  - service: cover.close_cover
    entity_id: cover.window_shutter_00_vse
  id: 21254e3edb0e428b9d8f634033a1d7c1
- alias: Close shutters 4,5 at -3 degrees
  trigger:
    platform: numeric_state
    entity_id: sun.sun
    value_template: '{{ state_attr(''sun.sun'', ''elevation'') }}'
    below: -2
  action:
  - service: cover.close_cover
    entity_id: cover.window_shutter_04_tualet
  - service: cover.close_cover
    entity_id: cover.window_shutter_05_kukhnia

Yes they can. Have a look at the history for your sun elevation. It can change from 0 to -6 in one step. Which would trigger both automations at the same time.

Ok, thanks! Hope this update will clarify such situation with sudden triggering because to me it is happening not first time…

See my post above. The sun elevation attribute does not update very often.

EDIT: actually that’s probably not it. Looking at the PR:

The elevation update should still occur every 1° at the times/values your automations are set to trigger.

Unless you missed the 0 to 6° elevation while restarting. Then the next sun elevation update would be 8 minutes later and trigger both automations at the same time.

What I can see in History the angle was below 0 all this period…

Template results are not restored when restarting.

So the first time the elevation updates after a restart both the trigger templates will evaluate to true (-32 is below both -2 and -5), triggering the automations.

“Template result” - do you mean status of automation? is it stored somewhere?

After a restart the value of these trigger templates:

value_template: '{{ state_attr(''sun.sun'', ''elevation'') }}'

Will be ‘unknown’ until the sun.sun integration updates.

As soon as sun.sun updates they will become some value. In this case -32°, triggering the automations.

I think the way around this is to create a template sensor for elevation. Then use the entity id of this sensor in a numeric state trigger (rather than a value template as you have now).

Template sensors are restored on restart (I think… I’m almost certain).

I have such sensors for my sonoff POW R2 values (current, energy etc) . Right after HA restart they all are set to ‘unknown’ . Then first MQTT msg arrives from the device to HA the sensors are updated with real values…

Yep. MQTT is a different kettle of fish. You can set the retain flag on those sensors (on the device that sends them) to fix that.

“Retain” is not a flag for sensor config but it should arrive as part of State msg. no?

Correct which is why I said:

You have to be careful what you set to retain though. See:

Just a related FYI: