I’m tearing my hair out trying to call a script from an automation. It is probably something simple but I’m just not seeing it so any help would be very welcome please.
As good an explanation as I have ever read, why doesn’t the documentation explain it as well as that ?
Normally I just blunder around till I get a format that works, and then blindly follow that format.
Since I have moved to packages this has become a LOT simpler.
But on the forum, dealing with all different types of user with all types of configuration, it is a nightmare trying to remember possible permutations that ‘may’ work
@tom_l thank you so much for that very, very useful response. It works! I spent hours and hours over the last few days trying to figure out what I was doing wrong and it was so simple in the end!
@Mutt I agree, I find I read and re-read the various help pages but have never seen it expressed as clearly as Tom did above.
By the way, at the risk of going off topic! - can I ask what this means “Since I have moved to packages this…” What does moving to packages mean?
Do a search on packages.
But here’s the link to the docs : -
Basically you don’t need automation.yaml, sensors.yaml, script.yaml etc. anymore. You just have packages. Each package has everything it it (well some packages have overlaps but …)
I have a package for my bedroom 1 called light_bed1.yaml another for light_bed2.yaml etc. I have several picore and amp players in boxes controlled by a z-wave switch, so the first box has a package and it’s written so you can copy it, search and replace key strings and save as box 2, rinse and repeat. I have 37 packages (more being added). Here is an example.
input_boolean:
ib_switch_pifi01_timer_enable:
name: Timer Enable
#initial: on
icon: mdi:timer
ib_switch_pifi01_timeslot1_enable:
name: Time Slot 1 Enable
#initial: on
icon: mdi:clock-outline
ib_switch_pifi01_timeslot2_enable:
name: Time Slot 2 Enable
#initial: on
icon: mdi:clock-outline
input_number:
in_switch_pifi01_timer:
name: On Timer (mins)
#initial: 30
min: 1
max: 360
step: 1
mode: box
icon: mdi:alarm
input_datetime:
id_switch_pifi01_tmeslt1_on:
name: Time Slot 1 On Time
has_time: true
#initial: "09:00:00"
icon: mdi:clock-start
id_switch_pifi01_tmeslt1_off:
name: Time Slot 1 Off Time
has_time: true
#initial: "10:00:00"
icon: mdi:clock-end
id_switch_pifi01_tmeslt2_on:
name: Time Slot 2 On Time
has_time: true
#initial: "18:00:00"
icon: mdi:clock-start
id_switch_pifi01_tmeslt2_off:
name: Time Slot 2 Off Time
has_time: true
#initial: "19:00:00"
icon: mdi:clock-end
automation:
#name: Switch H1 Off Delay
- alias: au_switch_pifi01_offdelay
trigger:
- platform: state
entity_id: switch.fib_fgwpef_wallplug_f01
to: 'on'
condition:
- condition: state
entity_id: input_boolean.ib_switch_pifi01_timer_enable
state: 'on'
action:
- service: script.turn_off
entity_id: script.sc_switch_pifi01_timer
- service: script.sc_switch_pifi01_timer
#radio button (toggle) timer to time slot
- alias: au_switch_pifi01_radiob_tmr_to_slot
trigger:
- platform: state
entity_id: input_boolean.ib_switch_pifi01_timer_enable
to: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.ib_switch_pifi01_timeslot1_enable, input_boolean.ib_switch_pifi01_timeslot2_enable
#radio button (toggle) time slot to timer
- alias: au_switch_pifi01_radiob_slot_to_tmr
trigger:
- platform: state
entity_id: input_boolean.ib_switch_pifi01_timeslot1_enable, input_boolean.ib_switch_pifi01_timeslot2_enable
to: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.ib_switch_pifi01_timer_enable
#turning off timer enable cancels timer
- alias: au_switch_pifi01_cancel_tmr
trigger:
- platform: state
entity_id: input_boolean.ib_switch_pifi01_timer_enable
to: 'off'
action:
- service: script.turn_off
entity_id: script.sc_switch_pifi01_timer
#time slot 1 on
- alias: au_switch_pifi01_ontime1
trigger:
- platform: template
value_template: "{{ states('sensor.time') == states('input_datetime.id_switch_pifi01_tmeslt1_on') [0:5] }}"
condition:
- condition: state
entity_id: input_boolean.ib_switch_pifi01_timeslot1_enable
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.fib_fgwpef_wallplug_f01
#time slot 1 off
- alias: au_switch_pifi01_offtime1
trigger:
- platform: template
value_template: "{{ states('sensor.time') == states('input_datetime.id_switch_pifi01_tmeslt1_off') [0:5] }}"
condition:
- condition: state
entity_id: input_boolean.ib_switch_pifi01_timeslot1_enable
state: 'on'
action:
- service: switch.turn_off
entity_id: switch.fib_fgwpef_wallplug_f01
#time slot 2 on
- alias: au_switch_pifi01_ontime2
trigger:
- platform: template
value_template: "{{ states('sensor.time') == states('input_datetime.id_switch_pifi01_tmeslt2_on') [0:5] }}"
condition:
- condition: state
entity_id: input_boolean.ib_switch_pifi01_timeslot2_enable
state: 'on'
action:
- service: switch.turn_on
entity_id: switch.fib_fgwpef_wallplug_f01
#time slot 2 off
- alias: au_switch_pifi01_offtime2
trigger:
- platform: template
value_template: "{{ states('sensor.time') == states('input_datetime.id_switch_pifi01_tmeslt2_off') [0:5] }}"
condition:
- condition: state
entity_id: input_boolean.ib_switch_pifi01_timeslot2_enable
state: 'on'
action:
- service: switch.turn_off
entity_id: switch.fib_fgwpef_wallplug_f01
#name: Switch Pi-Fi-01 Off Cancels Timer
- alias: au_switch_pifi01_offcancelstimer
trigger:
- platform: state
entity_id: switch.fib_fgwpef_wallplug_f01
to: 'off'
action:
- service: script.turn_off
entity_id: script.sc_switch_pifi01_timer
script:
sc_switch_pifi01_timer:
alias: Switch Pi-Fi-01 Timer Script
sequence:
- delay: "00:{{ states('input_number.in_switch_pifi01_timer') | int }}:00"
- service: switch.turn_off
entity_id: switch.fib_fgwpef_wallplug_f01
So one format for everything, need a new automation? , copy it from something similar, and fettle it.