and have changed the code to include extra triggers. Everything is working as I want except for 1 thing:
The master switch is turning off if any 1 of the slave switches turn off. I need to keep the master switch on if any of the slaves switches are on. I only want the master to turn off if slave1 and slave 2 and slave 3 and slave 4 and slave 5 turn off.
Could anyone help with what I’d need to change to get this working?
blueprint:
name: Master switch to off other switches
description: Master switch to control other slave switches (when master turned off,
then all slaves switches goes off as well. When any slave switch is “on” then
master switch is on as well. For example one switch next to outdoor to turn off
all light in the house when leaving a home, or one switch next the bed to turn
off all lights when I go sleep.
domain: automation
input:
switch_master:
name: Master Switch
selector:
entity:
domain:
- switch
multiple: false
switch_slave1:
name: Slave Switch 1
selector:
entity:
domain:
- switch
multiple: false
switch_slave2:
name: Slave Switch 2
selector:
entity:
domain:
- switch
multiple: false
switch_slave3:
name: Slave Switch 3
selector:
entity:
domain:
- switch
multiple: false
switch_slave4:
name: Slave Switch 4
selector:
entity:
domain:
- switch
multiple: false
switch_slave5:
name: Slave Switch 5
selector:
entity:
domain:
- switch
multiple: false
source_url: Master switch to control other slave switches (when master turned off, then all slaves switches goes off as well. When any slave switch is "on" then master switch is on as well. For example one switch next to outdoor to turn off all light in the house when leaving a home, or one switch next the bed to turn off all lights when I go sleep. · GitHub
variables:
switch_master: !input switch_master
switch_slave1: !input switch_slave1
switch_slave2: !input switch_slave2
switch_slave3: !input switch_slave3
switch_slave4: !input switch_slave4
switch_slave5: !input switch_slave5
switch_slaves:
Thanks for the tip, sorry I missed that. I’ve read the FAQ but not sure what I need to do. Can I upload the code in .yaml or .txt file?
I’ll try to paste the text again using code blocks, but it seems to appear the same way.
Sorry, I know this is basic but I’d really like to share the code and I expect I’m missing something small
This will do what you want with any number of slave switches.
blueprint:
name: Master switch to off other switches
description: Master switch to control other slave switches (when master turned off,
then all slaves switches goes off as well. When any slave switch is "on" then
master switch is on as well. For example one switch next to outdoor to turn off
all light in the house when leaving a home, or one switch next the bed to turn
off all lights when I go sleep.
domain: automation
input:
switch_master:
name: Master Switch
selector:
entity:
domain:
- switch
multiple: false
switch_slaves:
name: Slave Switches
selector:
entity:
domain:
- switch
multiple: true
variables:
switch_master: !input switch_master
switch_slaves: !input switch_slaves
slaves_on: >
{{ switch_slaves | select('is_state', 'on') | list | count > 0 }}
master_on: >
{{ is_state(switch_master, 'on') }}
## TRIGGERS ##
trigger:
- id: master
platform: state
entity_id: !input switch_master
from: 'on'
to: 'off'
- id: slave
platform: state
entity_id: !input switch_slaves
from: 'off'
to: 'on'
- id: slave
platform: state
entity_id: !input switch_slaves
from: 'on'
to: 'off'
action:
- if: "{{ trigger.id == 'master' and slaves_on }}"
then:
- service: switch.turn_off
target:
entity_id: !input switch_slaves
else:
- if: >
{{ trigger.id == 'slave' and ((slaves_on and not master_on) or (not slaves_on and master_on)) }}
then:
- service: switch.turn_{{ 'on' if slaves_on else 'off' }}
target:
entity_id: !input switch_master
EDIT: Disclaimer, it may not work with 1 slave switch, minor alteration for that…
blueprint:
name: Master switch to off other switches
description: Master switch to control other slave switches (when master turned off,
then all slaves switches goes off as well. When any slave switch is "on" then
master switch is on as well. For example one switch next to outdoor to turn off
all light in the house when leaving a home, or one switch next the bed to turn
off all lights when I go sleep.
domain: automation
input:
switch_master:
name: Master Switch
selector:
entity:
domain:
- switch
multiple: false
input_slaves:
name: Slave Switches
selector:
entity:
domain:
- switch
multiple: true
variables:
switch_master: !input switch_master
input_slaves: !input switch_slaves
slave_switches: >
{{ [ input_slaves ] if input_slaves is string else input_slaves }}
slaves_on: >
{{ switch_slaves | select('is_state', 'on') | list | count > 0 }}
master_on: >
{{ is_state(switch_master, 'on') }}
## TRIGGERS ##
trigger:
- id: master
platform: state
entity_id: !input switch_master
from: 'on'
to: 'off'
- id: slave
platform: state
entity_id: !input switch_slaves
from: 'off'
to: 'on'
- id: slave
platform: state
entity_id: !input switch_slaves
from: 'on'
to: 'off'
action:
- if: "{{ trigger.id == 'master' and slaves_on }}"
then:
- service: switch.turn_off
target:
entity_id: !input switch_slaves
else:
- if: >
{{ trigger.id == 'slave' and ((slaves_on and not master_on) or (not slaves_on and master_on)) }}
then:
- service: switch.turn_{{ 'on' if slaves_on else 'off' }}
target:
entity_id: !input switch_master