This setup relies on having Zigbee switches, connected to zigbee2mqtt. systemd timers just publish messages to the MQTT broker and z2m acts on them.
Setup the systemd unit files, service and timers. Remember to daemon-reload
afterwards.
(The names are a leftover from my 433MHz RF switch)
# head -100 /etc/systemd/system/lightswitch*
==> /etc/systemd/system/lightswitch-off.timer <==
[Unit]
Description=sends RF switch signal OFF
[Install]
WantedBy=timers.target
[Timer]
OnCalendar=*-*-* 23:45:00
RandomizedDelaySec=15min
[email protected]
==> /etc/systemd/system/lightswitch-on.timer <==
[Unit]
Description=sends RF switch signal ON
[Install]
WantedBy=timers.target
[Timer]
OnCalendar=*-*-* 19:08:00
RandomizedDelaySec=8min
[email protected]
==> /etc/systemd/system/[email protected] <==
[Unit]
Description=sends RF switch signal
[Service]
Type=oneshot
Environment=MQTT_USER=bob
Environment=MQTT_PASS=s3cr3tPassw0rd
Environment=MQTT_TOPIC=zigbee2mqtt/0x54ef111000441133/set
ExecStart=mosquitto_pub -i systemd_timer -t "${MQTT_TOPIC}" -u ${MQTT_USER} -P ${MQTT_PASS} -m '{"state_right":"%i"}'
Enable the timers:
# systemctl enable --now lightswitch-on.timer lightswitch-off.timer
Created symlink /etc/systemd/system/timers.target.wants/lightswitch-on.timer → /etc/systemd/system/lightswitch-on.timer.
Created symlink /etc/systemd/system/timers.target.wants/lightswitch-off.timer → /etc/systemd/system/lightswitch-off.timer.
Check the status of the timers:
# systemctl status lightswitch-{on,off}.timer
● lightswitch-on.timer - sends RF switch signal ON
Loaded: loaded (/etc/systemd/system/lightswitch-on.timer; enabled; vendor preset: disabled)
Active: active (waiting) since Fri 2023-01-20 18:31:05 +08; 4s ago
Trigger: Fri 2023-01-20 19:09:45 +08; 38min left
● lightswitch-off.timer - sends RF switch signal OFF
Loaded: loaded (/etc/systemd/system/lightswitch-off.timer; enabled; vendor preset: disabled)
Active: active (waiting) since Fri 2023-01-20 18:31:05 +08; 4s ago
Trigger: Fri 2023-01-20 23:54:32 +08; 5h 23min left
You can also manually trigger them by typing:
# systemctl start lightswitch@ON