HI,
using:
switch:
- platform: template
switches:
early_night:
friendly_name: 'Early night'
value_template: >
{{is_state('input_boolean.early_night','on')}}
turn_on:
- service: automation.turn_off
entity_id:
- automation.switch_bedside_table_off_when_no_motion
- automation.switch_bedside_table_on_when_motion
- service: scene.turn_on
entity_id: scene.early_night
- service: switch.turn_on
entity_id: switch.master_bed_outlet
turn_off:
- service: automation.turn_on
entity_id:
- automation.switch_bedside_table_off_when_no_motion
- automation.switch_bedside_table_on_when_motion
doesnt seem to turn-on/off the specified actions on flipping the boolean. I can see the boolean change state, but none of the actions takes place.
Have I overlooked anything in the config? According to https://www.home-assistant.io/components/switch.template/ the switch should act upon state-changing of the template. which doesn’t happen…
config checks valid.
please have a look for me.
tom_l
August 22, 2019, 9:33pm
2
turn_on
(action )(Required)
Defines an action to run when the switch is turned on.
‘an action’ implies singular not multiple actions.
Replace your multiple actions with a script that does them. Or use an automation instead of a template switch. This does look much more like an automation.
a yes, I missed that indeed, will create 2 little scripts then, easy enough. Reason I use the template switch is that the on and off actions aren’t mirrored exactly. I would need 2 automations to do what I can do with 1 template switch (of course I now need to extra scripts, but they are reusable …)
thanks for your keen eye!
changed to:
early_night:
friendly_name: 'Early night'
value_template: >
{{is_state('input_boolean.early_night','on')}}
turn_on:
- service: script.early_night_on
turn_off:
- service: script.early_night_off
and scripts:
early_night_on:
alias: 'Early night on'
sequence:
- service: automation.turn_off
entity_id:
- automation.switch_bedside_table_off_when_no_motion
- automation.switch_bedside_table_on_when_motion
- service: scene.turn_on
entity_id: scene.early_night
- service: switch.turn_on
entity_id: switch.master_bed_outlet
early_night_off:
alias: 'Early night off'
sequence:
- service: automation.turn_on
entity_id:
- automation.switch_bedside_table_off_when_no_motion
- automation.switch_bedside_table_on_when_motion
which is even better. since I can now also add conditions if needed, and expand easier
hope this works now. never am sure if I need to switch or flip the input_boolean. Since I don’t explicitly change the input_boolean anywhere…
update
well, it doesn’t work. the switch won’t activate the turn_on/off services. confess I dont really understand why…
changed it into an automation after all:
automation:
- alias: 'Early night'
id: 'Early night'
trigger:
platform: state
entity_id: input_boolean.early_night
condition: []
action:
service_template: >
script.early_night_{{trigger.to_state.state}}
probably shortest and most effective as it can get.
I’ll check your suggestion as a solution, so thanks!
2 Likes