I’m logging out some values using a node-function, and homeassistant is really delaying the state changes, not sure why.
This is how I simply setup the logging mechanism (events are stored on the contex of the function node)
Here are the logs (note that the timestamp is one hour less because is on my local timezone, while the HA timestamps are UTC):
[
{
"timestamp": "05:07:45",
"old": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "off",
"last_changed": "2021-01-31T15:51:57.903318+00:00",
"last_updated": "2021-01-31T15:51:57.903318+00:00",
"original_state": "off"
},
"new": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "off",
"last_changed": "2021-01-31T15:51:57.903318+00:00",
"last_updated": "2021-01-31T16:07:44.983673+00:00",
"original_state": "off"
}
},
{
"timestamp": "05:07:45",
"old": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "off",
"last_changed": "2021-01-31T15:51:57.903318+00:00",
"last_updated": "2021-01-31T16:07:44.983673+00:00",
"original_state": "off"
},
"new": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "on",
"last_changed": "2021-01-31T16:07:44.984114+00:00",
"last_updated": "2021-01-31T16:07:44.984114+00:00",
"original_state": "on"
}
},
{
"timestamp": "05:10:17",
"old": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "on",
"last_changed": "2021-01-31T16:07:44.984114+00:00",
"last_updated": "2021-01-31T16:07:44.984114+00:00",
"original_state": "on"
},
"new": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "on",
"last_changed": "2021-01-31T16:07:44.984114+00:00",
"last_updated": "2021-01-31T16:10:17.491604+00:00",
"original_state": "on"
}
},
{
"timestamp": "05:10:17",
"old": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "on",
"last_changed": "2021-01-31T16:07:44.984114+00:00",
"last_updated": "2021-01-31T16:10:17.491604+00:00",
"original_state": "on"
},
"new": {
"entity_id": "binary_sensor.motion_2_occupancy",
"state": "off",
"last_changed": "2021-01-31T16:10:17.492355+00:00",
"last_updated": "2021-01-31T16:10:17.492355+00:00",
"original_state": "off"
}
}
]
Looking at the logs, there was a gap of 3 minutes between the first two messages and the last two, where it went from on to off. During that time, there were motion on the WC, but it was just ignored.
Maybe the sensor goes to sleep if it does not detects motion exactly one minute after waking up again? Or maybe the opposite, it does not report anything until something “changes” ? In which case my entire flow is stupid, and my only option is to wait for the sensor to tell me “there is no motion”.