Hmm… strange… The trace shows that the automation hasn’t started. Are you sure no other executions are active? Can you examine all the latest traces of the automation? Perhaps a previous instance of the automation was running and turned off the light. Let me know. I’ll try to run some more tests at home, but looking at the trace, I can’t explain the behavior.
Let me know!
Thanks
Will do this evening when I get back from work
@bladerunner70 just tested again and it seems to work. Had to restart HA after updating template
I’m having a problem with this automation. I restarted HA, deleted the automation, then re-created it. It worked one time, now it’s going back to this error again. The Z-wave light itself is working fine, including accepting remote on-off commands.
Hi!
My Pre-sunset settings seem to be ignored. Light is only activated after sunset and not already two hours before. Any ideas?
Thank you very much!
Best regards,
Volker
{
"trace": {
"last_step": "condition/0/conditions/1/conditions/2/conditions/1",
"run_id": "7161f85a67d7084ecaa2c8a380c758c3",
"state": "stopped",
"script_execution": "failed_conditions",
"timestamp": {
"start": "2025-04-16T17:37:49.366109+00:00",
"finish": "2025-04-16T17:37:49.367122+00:00"
},
"domain": "automation",
"item_id": "1738952995297",
"trigger": "state of binary_sensor.bewegung_wohnzimmer",
"trace": {
"trigger/0": [
{
"path": "trigger/0",
"timestamp": "2025-04-16T17:37:49.366533+00:00",
"changed_variables": {
"this": {
"entity_id": "automation.lightstrip_bei_bewegung_an",
"state": "on",
"attributes": {
"id": "1738952995297",
"last_triggered": "2025-04-16T05:36:30.924693+00:00",
"mode": "restart",
"current": 0,
"icon": "hue:lightstrip",
"friendly_name": "Lightstrip bei Bewegung an"
},
"last_changed": "2025-04-16T16:51:23.352821+00:00",
"last_reported": "2025-04-16T16:51:23.352821+00:00",
"last_updated": "2025-04-16T16:51:23.352821+00:00",
"context": {
"id": "01JRZR6B2RMT8265F2T3CFSDW7",
"parent_id": null,
"user_id": null
}
},
"trigger": {
"id": "0",
"idx": "0",
"alias": null,
"platform": "state",
"entity_id": "binary_sensor.bewegung_wohnzimmer",
"from_state": {
"entity_id": "binary_sensor.bewegung_wohnzimmer",
"state": "off",
"attributes": {
"entity_id": [
"binary_sensor.bewegungsmelder_wohnzimmer_2_motion",
"binary_sensor.shelly_b_59cc_motion"
],
"device_class": "motion",
"friendly_name": "Bewegung Wohnzimmer"
},
"last_changed": "2025-04-16T17:14:33.388965+00:00",
"last_reported": "2025-04-16T17:14:33.388965+00:00",
"last_updated": "2025-04-16T17:14:33.388965+00:00",
"context": {
"id": "01JRZSGRHCEXKCB3ZAM6SQC8B5",
"parent_id": null,
"user_id": null
}
},
"to_state": {
"entity_id": "binary_sensor.bewegung_wohnzimmer",
"state": "on",
"attributes": {
"entity_id": [
"binary_sensor.bewegungsmelder_wohnzimmer_2_motion",
"binary_sensor.shelly_b_59cc_motion"
],
"device_class": "motion",
"friendly_name": "Bewegung Wohnzimmer"
},
"last_changed": "2025-04-16T17:37:49.365901+00:00",
"last_reported": "2025-04-16T17:38:23.740170+00:00",
"last_updated": "2025-04-16T17:37:49.365901+00:00",
"context": {
"id": "01JRZTVBSKAZFPER9NMK7NW9NZ",
"parent_id": null,
"user_id": null
}
},
"for": null,
"attribute": null,
"description": "state of binary_sensor.bewegung_wohnzimmer"
},
"dusk_start_hour": 2,
"dusk_start_minute": 0,
"rising_start_hour": 0,
"rising_start_minute": 0,
"use_weather": false,
"skip_light_on": false,
"target_lights": {
"entity_id": "light.lightstrip"
},
"force_skip": false,
"sun_rising": "2025-04-16 16:51:14.936965+00:00",
"sun_dusk": "2025-04-16T18:36:14.365245+00:00",
"wheater_sensor": "weather.forecast_home",
"no_sunny_wheater": false
}
}
],
"condition/0": [
{
"path": "condition/0",
"timestamp": "2025-04-16T17:37:49.366566+00:00",
"result": {
"result": false
}
}
],
"condition/0/conditions/0": [
{
"path": "condition/0/conditions/0",
"timestamp": "2025-04-16T17:37:49.366590+00:00",
"result": {
"result": true,
"entities": []
}
}
],
"condition/0/conditions/1": [
{
"path": "condition/0/conditions/1",
"timestamp": "2025-04-16T17:37:49.366678+00:00",
"result": {
"result": false
}
}
],
"condition/0/conditions/1/conditions/0": [
{
"path": "condition/0/conditions/1/conditions/0",
"timestamp": "2025-04-16T17:37:49.366697+00:00",
"result": {
"result": false,
"entities": []
}
}
],
"condition/0/conditions/1/conditions/1": [
{
"path": "condition/0/conditions/1/conditions/1",
"timestamp": "2025-04-16T17:37:49.366758+00:00",
"result": {
"result": false,
"entities": []
}
}
],
"condition/0/conditions/1/conditions/2": [
{
"path": "condition/0/conditions/1/conditions/2",
"timestamp": "2025-04-16T17:37:49.366847+00:00",
"result": {
"result": false
}
}
],
"condition/0/conditions/1/conditions/2/conditions/0": [
{
"path": "condition/0/conditions/1/conditions/2/conditions/0",
"timestamp": "2025-04-16T17:37:49.366870+00:00",
"result": {
"result": true,
"entities": []
}
}
],
"condition/0/conditions/1/conditions/2/conditions/1": [
{
"path": "condition/0/conditions/1/conditions/2/conditions/1",
"timestamp": "2025-04-16T17:37:49.367008+00:00",
"result": {
"result": false,
"entities": []
}
}
]
},
"config": {
"mode": "restart",
"max_exceeded": "silent",
"variables": {
"dusk_start_hour": 2,
"dusk_start_minute": 0,
"rising_start_hour": 0,
"rising_start_minute": 0,
"use_weather": false,
"skip_light_on": false,
"target_lights": {
"entity_id": "light.lightstrip"
},
"force_skip": "{{ skip_light_on and\n (expand(\n (([] if target_lights.device_id is undefined\n else target_lights.device_id | device_entities\n if target_lights.device_id is string\n else target_lights.device_id | map('device_entities') | sum(start=[]) )\n +\n ([] if target_lights.entity_id is undefined\n else [target_lights.entity_id]\n if target_lights.entity_id is string\n else target_lights.entity_id ))\n | select('search', '^light\\.') | list\n ) | selectattr('state', 'eq', 'on') | list | length > 0)\n}}\n",
"sun_rising": "{% if (states.sun.sun.state == \"above_horizon\") %}\n {{ states.sun.sun.last_changed }}\n{%- else -%}\n {{ states.sun.sun.attributes.next_rising }}\n{%- endif %}\n",
"sun_dusk": "{% if (states.sun.sun.state == \"above_horizon\") %}\n {{ states.sun.sun.attributes.next_dusk }}\n{%- else -%}\n {{ states.sun.sun.last_changed }}\n{%- endif %}\n",
"wheater_sensor": "weather.forecast_home",
"no_sunny_wheater": "{{ states(wheater_sensor) != 'sunny' and use_weather }}\n"
},
"triggers": {
"platform": "state",
"entity_id": "binary_sensor.bewegung_wohnzimmer",
"from": "off",
"to": "on"
},
"conditions": [
{
"condition": "and",
"conditions": [
{
"condition": "template",
"value_template": "{{ not force_skip }}"
},
{
"condition": "or",
"conditions": [
{
"condition": "template",
"value_template": false
},
{
"condition": "template",
"value_template": "{{ no_sunny_wheater }}"
},
{
"condition": "and",
"conditions": [
"{{ as_timestamp(now()) >= ((as_timestamp(sun_dusk) - dusk_start_hour*3600 - dusk_start_minute*60) )}}",
"{{ as_timestamp(now()) < ((as_timestamp(sun_rising) + rising_start_hour*3600 + rising_start_minute*60) )}}"
]
}
]
}
]
}
],
"actions": [
{
"target": {
"entity_id": "light.lightstrip"
},
"action": "light.turn_on"
},
{
"wait_for_trigger": {
"platform": "state",
"entity_id": "binary_sensor.bewegung_wohnzimmer",
"from": "on",
"to": "off"
},
"timeout": {
"hours": 0,
"minutes": 0,
"seconds": 0,
"milliseconds": 0
}
},
{
"delay": 3600
},
{
"target": {
"entity_id": "light.lightstrip"
},
"action": "light.turn_off"
}
],
"id": "1738952995297",
"alias": "Lightstrip bei Bewegung an",
"description": ""
},
"blueprint_inputs": {
"id": "1738952995297",
"alias": "Lightstrip bei Bewegung an",
"description": "",
"use_blueprint": {
"path": "giannisigalotti/motion-activated-light.yaml",
"input": {
"motion_entity": "binary_sensor.bewegung_wohnzimmer",
"light_target": {
"entity_id": "light.lightstrip"
},
"no_motion_wait": 3600,
"wheater_handling": false,
"wheater_entity": "weather.forecast_home",
"sunset_start_hh": 2,
"timeout": 0,
"sunset_start_mm": 0
}
}
},
"context": {
"id": "01JRZTVBSPADY02A40Q9F66VS8",
"parent_id": "01JRZTVBSKAZFPER9NMK7NW9NZ",
"user_id": null
}
},
"logbookEntries": []
}
Dear Volker - same problem in my installation. I am trying different ways but nothing changed as expected. My next try is to work only with minutes.
regards ingmar
Dear Ingmar,
I also tried minutes only, that didn’t work, too. Now I am using my own automation with brightness as condition…
Best regards, Volker
Hallo Volker, ich glaube wir können in dt. schreiben. Ich habe mir schon Sorgen gemacht… :). Vielleicht liest der Autor ja mit. ( spricht natürlich wieder für Englisch)
Dann hätte ich mir die Geschichte mit den Minuten ja sparen können. Mein Eindruck - jegliche Einstellung sunrise / sunset wird ignoriert. Aktiviert / Deaktiviert wird zu den Zeiten, die aus HA kommen.
GRUß aus Cuxhaven, Ingmar
Hallo Volker,
hast Du auf irgendeinem Weg Kontakt zum Autor Gianni gehabt??
Gruesse Ingmar
Good idea! Excuse me for delay . I’ll try to add also this to the blueprint ASAP
This seems like a very strange error to me. The code at this point is really simple — it just calls the service to turn on the light.
Could I ask you to describe the behavior more clearly?
Does the light turn on and then you receive the error, or does the light not turn on at all?
If the light doesn’t turn on, have you tried using a different light (not based on Z-Wave)?
Let me know what happens and I’ll try to help you to fix.
Thanks
@dl3hby @muesli79 excuse me for delay!
Now I try to analyze what is happening. Obviously if you have a brightness sensor you can use that but here the idea was to support also motion sensors with no brightness sensor.
Anyway let me check better the issue.
I try to answer ASAP
Thanks
Good morning Gianni and first of all - thank you for helping. The situation in my installation - both offset times are completely ignored. Minutes and hours do not change the working time. Rest work as expected.
Light is going on / off.
I startet with the wish to use the brightness sensor of the motion sensor. The problen there - the sensor is updating once per hour and at every motion detection. ( not able to change that) So that’s the story to look around and to try your blueprint.
Again - thank you for analyzing and regards from the northern part of germany!
Ingmar
Hi, it’s working now - thanks.
Hi Ingmar, I’m just looking at the code and at @muesli79 trace and seems to me that the condition
value {{ states.sun.sun.last_changed }} isn’t correctly evaluated because the values
“sun_rising”: “2025-04-16 16:51:14.936965+00:00”,
are wrong for sure (the trigger is fired at “2025-04-16T17:37:49.366109+00:00”).
The point is that documentation reports that last_changed is evaluated only when sun.sun state changes form / to above_horizon, and so, to me isn’t clear why sun_raising assume that value.
I’ll try to change the evaluation of sun_rising to try to fix.
Stay tuned.
Thanks
Hi Gianni,
thank you very much for your help.
BTW, I didn’t use a brightness sensor for your blueprint, I just use it now for my quite simple automation as condition instead of weather and time.
Best regards, Volker
I wanted to use your blueprint, but it found only motion detection sensor on my camera, not motion sensors.
Hi, here the choice was to show only the sensors belonging to “motion” class. If you need I can chenge a bit the filter to let you add also the “presence” class sensors. Is this what you need?
My sensors are occupancy
Thank you very much for your automation.
Would it be too difficult to add conditions before the lights are turned on?
My use case is as follows: I have a main, strong, manually activated light. I also have some weaker helper lights. The main light is turned on and off manually, and I don’t need to activate the weaker ones if the main light was already on.
Or do you believe that a template is easier?
