@penright wrote:
Trying to learn HA automation. Most of my automation to this point has been in AppDeamon scripts. So since it getting close to Christmas, I thought I would give it a try with that as the theme. I thought I would post it to see if there is a better mousetrap. “Better” being relative to what end. More reliable? Smaller? Easier to read? While do my searches I learned to be careful to watch the dates on posts and examples. Lots of improvements over the years mean something may work, but is it the best practice. For example, after the -service line in an automation if you just have an entity then you don’t need data/data_template. But anything else you do, so why not add data/data_template even if you don’t need to for “best practices”.
I created two different timers. One runs all night and the other shuts off in the middle of the night and turns back on for the morning.
So from the control panel, you can control the Start/End dates (not wired up yet). Turn the automation off/on and both timers state.
No one is going to hurt my feelings by pointing out some part as a stupid way of doing it. The point here is to learn.###################################################################################### #I thought about adding a start/end date #If I ever do all it has to do is control the run automation switch (christmas_lights_run) ###################################################################################### input_datetime: start_christmas_lights: name: "Start Christmas Lights" has_date: true has_time: false end_christmas_lights: name: "End Christmas Lights" has_date: true has_time: false ###################################################################################### ###################################################################################### #One switch is control the automation and the other two are for the lights ###################################################################################### input_boolean: christmas_lights_run: name: "Christmas Lights Run Automations" christmas_lights_all_night: name: "Christmas Lights All Night" christmas_lights_night_morning: name: "Christmas Lights Night then Morning" ###################################################################################### automation: #################################################################################### #These 4 automation is what actually controls the devices. #Add any other devices to the both the correct on/off action #They are contoled via the two input boolean switches #################################################################################### - alias: christmas_lights_all_night_switch_on trigger: - platform: state entity_id: input_boolean.christmas_lights_all_night to: 'on' action: - service: light.turn_on data: entity_id: light.christmas_lights_outside - alias: christmas_lights_night_morning_switch_on trigger: - platform: state entity_id: input_boolean.christmas_lights_night_morning to: 'on' action: - service: light.turn_on data: entity_id: light.christmas_lights_tree - alias: christmas_lights_all_night_switch_off trigger: - platform: state entity_id: input_boolean.christmas_lights_all_night to: 'off' action: - service: light.turn_off data: entity_id: light.christmas_lights_outside - alias: christmas_lights_night_morning_switch_off trigger: - platform: state entity_id: input_boolean.christmas_lights_night_morning to: 'off' action: - service: light.turn_off data: entity_id: light.christmas_lights_tree ############################################################################################### #################################################################################### #These 2 automation switch on/off the automation that actually controls the input_boolean #################################################################################### - alias: christmas_lights_automations_on trigger: - platform: state entity_id: 'input_boolean.christmas_lights_run' to: 'on' action: - service: automation.turn_on data: entity_id: automation.christmas_lights_on_sunset - service: automation.turn_on data: entity_id: automation.christmas_lights_off_sunrise - service: automation.turn_on data: entity_id: automation.christmas_lights_off_midnight - service: automation.turn_on data: entity_id: automation.christmas_lights_on_atfour - alias: christmas_lights_automations_off trigger: - platform: state entity_id: 'input_boolean.christmas_lights_run' to: 'off' action: - service: automation.turn_off data: entity_id: automation.christmas_lights_on_sunset - service: automation.turn_off data: entity_id: automation.christmas_lights_off_sunrise - service: automation.turn_off data: entity_id: automation.christmas_lights_off_midnight - service: automation.turn_off data: entity_id: automation.christmas_lights_on_atfour ############################################################################################### #################################################################################### #These automations switch on/off the input_boolean that controls the lights #################################################################################### - alias: christmas_lights_on_sunset trigger: - platform: sun event: sunset offset: "+00:30:00" action: - service: input_boolean.turn_on data: entity_id: input_boolean.christmas_lights_all_night - service: input_boolean.turn_on data: entity_id: input_boolean.christmas_lights_night_morning - alias: christmas_lights_off_sunrise trigger: - platform: sun event: sunrise offset: "-00:30:00" action: - service: input_boolean.turn_off data: entity_id: input_boolean.christmas_lights_all_night - service: input_boolean.turn_off data: entity_id: input_boolean.christmas_lights_night_morning - alias: christmas_lights_off_midnight trigger: - platform: time at: "00:30:00" action: - service: input_boolean.turn_off data: entity_id: input_boolean.christmas_lights_night_morning - alias: christmas_lights_on_atfour trigger: - platform: time at: "04:00:00" action: - service: input_boolean.turn_on data: entity_id: input_boolean.christmas_lights_night_morning ###############################################################################################
Posts: 1
Participants: 1