Code for Node-Red
This little block of code is used in Node-Red as a part of Home Assistant.
It works by sending a timestamp every minute which is compared to input datetime we created earlier. If those two match, then it fires the command to turn on the light to green.
[{"id":"be751dd0.7d958","type":"api-call-service","z":"7486bd0f.d895e4","name":"Lamp green","server":"109a104b.db362","version":"1","debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.CHANGEME","data":"{\"color_name\":\"green\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":730,"y":1140,"wires":[[]]},{"id":"5e52b58d.875804","type":"function","z":"7486bd0f.d895e4","name":"Check input datetine","func":"const states = global.get('homeassistant').homeAssistant.states;\nconst now = new Date();\nconst alarm = states['input_datetime.CHANGEME'].attributes;\n\nif(now.getHours() === alarm.hour && now.getMinutes() === alarm.minute) {\n return msg;\n}","outputs":1,"noerr":0,"x":460,"y":1120,"wires":[["be751dd0.7d958"]]},{"id":"24c42171.19763e","type":"inject","z":"7486bd0f.d895e4","name":"","topic":"","payload":"","payloadType":"date","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":1120,"wires":[["5e52b58d.875804"]]},{"id":"109a104b.db362","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]
Code for YAML
So to use YAML you will need to install the Time sensor, see here.
Here is the example code from the Home Assistant documentation, modified for my example.
# Example configuration.yaml entry
# Turns on Liam light at the time specified.
automation:
trigger:
platform: template
value_template: "{{ states('sensor.time') == (state_attr('input_datetime.liam_wake', 'timestamp') | int | timestamp_custom('%H:%M', True)) }}"
action:
service: light.turn_on
entity_id: light.liams_lamp