One of the challenges as a new user to zwave JS was to create the automation YAML. I turned Microsoft Co-Pilot to help. Living north of the 50 parallel, I needed a script that would recognize the summer and winter seasons and turn my outside lights on and off depending on the different sunset and sunrise times. The script below does not work in December because I am using my soffit Christmas lights instead of my regular soffit lights. Below are the steps I did and the script Co-Pilot created. If you want to use this code copy it into Co-Pilot and ask to check that is ready to use as an automation YAML.
Steps
- Manually back up home assistant
- Open Microsoft Co-Pilot
- Type in zwave device commands in English. E.g.
a. For switch.front_porch_in_wall_paddle_switch_300s_2 create a automation YAML with comments, log to logbook so the entity is on between Sept 21 and March 20 for Tuesday, Wednesday and Thursday from 0615 to Sunrise plus 00:35:00 and on between Sept 21 and November 30 and January 1 and March 20 from sunset -00:45:00 and 2000 hours. Check status of light if on leave on. - Copilot YAML output
alias: Front Porch Seasonal Lighting Control
description: >
Controls the front porch paddle switch with seasonal morning and evening logic.
• Sept 21–Mar 20 (Tue–Thu): ON at 06:15, OFF at sunrise + 35 minutes
• Sept 21–Nov 30 & Jan 1–Mar 20: ON at sunset -45 minutes, OFF at 20:00
• Logs all actions to the logbook
mode: parallel
------------------------------------------------------------
TRIGGERS
------------------------------------------------------------
trigger:
Morning ON (06:15)
- platform: time
at: “06:15:00”
id: morning_on
Morning OFF (sunrise + 35 minutes)
- platform: sun
event: sunrise
offset: “00:35:00”
id: morning_off
Evening ON (sunset -45 minutes)
- platform: sun
event: sunset
offset: “-00:45:00”
id: evening_on
Evening OFF (20:00)
- platform: time
at: “20:00:00”
id: evening_off
------------------------------------------------------------
ACTION LOGIC
------------------------------------------------------------
action:
-
choose:
#######################################################################
1) MORNING LOGIC — Sept 21 → Mar 20 (Tue/Wed/Thu)
#######################################################################
-
conditions:
Date range: Sept 21 → Mar 20
- condition: template
value_template: >
{% set m = now().month %}
{% set d = now().day %}
{{ (m > 9) or (m == 9 and d >= 21) or (m < 3) or (m == 3 and d <= 20) }}
Only Tue/Wed/Thu
- condition: time
weekday: [tue, wed, thu]
Trigger must be morning ON
- condition: trigger
id: morning_on
sequence:
Turn ON (safe even if already ON)
- service: switch.turn_on
target:
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
Log action
- service: logbook.log
data:
name: Front Porch Lighting
message: “Morning ON (06:15, Tue–Thu, Sept 21–Mar 20)”
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
- condition: template
-
conditions:
Same date range
- condition: template
value_template: >
{% set m = now().month %}
{% set d = now().day %}
{{ (m > 9) or (m == 9 and d >= 21) or (m < 3) or (m == 3 and d <= 20) }}
Tue/Wed/Thu only
- condition: time
weekday: [tue, wed, thu]
Trigger must be morning OFF
- condition: trigger
id: morning_off
sequence:
Turn OFF at sunrise + 35
- service: switch.turn_off
target:
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
Log action
- service: logbook.log
data:
name: Front Porch Lighting
message: “Morning OFF (sunrise + 35 min, Tue–Thu)”
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
- condition: template
#######################################################################
2) EVENING LOGIC — Sept 21 → Nov 30 AND Jan 1 → Mar 20
#######################################################################
-
conditions:
Date range: Sept 21 → Nov 30 OR Jan 1 → Mar 20
- condition: template
value_template: >
{% set m = now().month %}
{% set d = now().day %}
{{ (m == 9 and d >= 21) or (m > 9 and m < 12) or
(m == 11 and d <= 30) or
(m == 1) or (m == 2) or (m == 3 and d <= 20) }}
Trigger must be evening ON
- condition: trigger
id: evening_on
sequence:
Turn ON (safe even if already ON)
- service: switch.turn_on
target:
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
Log action
- service: logbook.log
data:
name: Front Porch Lighting
message: “Evening ON (sunset -45, seasonal)”
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
- condition: template
-
conditions:
Same seasonal date range
- condition: template
value_template: >
{% set m = now().month %}
{% set d = now().day %}
{{ (m == 9 and d >= 21) or (m > 9 and m < 12) or
(m == 11 and d <= 30) or
(m == 1) or (m == 2) or (m == 3 and d <= 20) }}
Trigger must be evening OFF
- condition: trigger
id: evening_off
sequence:
Turn OFF at 20:00
- service: switch.turn_off
target:
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
Log action
- service: logbook.log
data:
name: Front Porch Lighting
message: “Evening OFF (20:00, seasonal)”
entity_id: switch.front_porch_in_wall_paddle_switch_300s_2
- condition: template
-