Hold on tight, this is going to be a long and weird post, I can’t even come up with a coherent title for what I am trying to do.
I will try to keep it simple at first and go into details later.
What I ultimately want is a button in lovelace that controls all my lights and show me the state of said lights (aka, if one light is on the icon has to be on). What I intended to use is a group entity, that works great, you can toggle it from a button and the icon responds how I want to.
.
Here is where my problem starts. I have a set of lights that isn’t controlled by a switch or an enity, but rather by an input select. I will go into details of why that is later on, but for now what you need to know is this input select has 4 options (off, on, left, right).
What I want is my enity group to show activity when either “on”, “left” or “right” are selected (and being inactive when “off” is selected) and also I want to be able to toggle the group enity so that when it’s toggled on the input select is set to “on” no matter what the starting point is and to “off” when the group is toggled off, no matter what the starting point is.
.
I think the way to achieve this would be with an input boolean but i can’t quite wrap my head around how to do it.
What I want said input boolean to do is:
-
Be on when either “on”, “left” or “right” are selected in the input select (and obviously the opposite (be off when “off” is selected in the imput select
-
Set the input select to either “on” or “off” when switched so that when the group toggle toggles the input boolean the light respond accordingly
As you may have noticed, if I write an automation that does that then it would end up with the toggle firing itself.
.
Now a little more about how this 4 state lights works currently. The lights are under a 4 way relay, said 4 way relay is fired by a sonoff mini, said sonoff mini is physically fired by another relay connected to the switch input of the sonoff mini.
(The sonoff mini is fired by a relay because I have multiple buttons in the same room and I don’t quite remember why I did it this way but it made it easier to wire multiple buttons to a single relay)
As for the “software” part. I have 2 separate input selects. One that represent the “actual” state of the lights, and one that rapresents the “desired” state of the lights. Normally these two input selects coincide, they don’t while an automation is running.
I have a script that switches the internal relay of the sonoff on and then off so that it fires the 4 way relay and selects the next option in the “desired” input select (the script is more of a convinience thing, I could have this actions performed by the automation directly)
alias: AAA Bottone Luci taverna
sequence:
- type: turn_on
device_id: daaba7920cac11ebbc493919bc264785
entity_id: switch.luci_taverna
domain: switch
- type: turn_off
device_id: daaba7920cac11ebbc493919bc264785
entity_id: switch.luci_taverna
domain: switch
- service: input_select.select_next
data: {}
entity_id: input_select.12345
mode: queued
icon: 'mdi:lightbulb'
max: 10
Then I have an automation, What it does is it fires the script (AAA Bottone Luci Taverna) until the “desired input select” is the same as the “actual input select”
The “desired input select” is: input_select.luci and has the options (“Spento” “Acceso” “Destra” “Sinistra”)
The “actual input select” is: input_select.12345 and has the options (0 1 2 3)
alias: AAA Tutte Luci Taverna
description: ''
trigger:
- platform: state
entity_id: input_select.luci
condition: []
action:
- choose:
- conditions:
- condition: state
state: Spento
entity_id: input_select.luci
sequence:
- repeat:
until:
- condition: state
entity_id: input_select.12345
state: '0'
sequence:
- service: script.bottone_luci_taverna
data: {}
- conditions:
- condition: state
entity_id: input_select.luci
state: Acceso
sequence:
- repeat:
until:
- condition: state
entity_id: input_select.12345
state: '1'
sequence:
- service: script.bottone_luci_taverna
data: {}
- conditions:
- condition: state
entity_id: input_select.luci
state: Destra
sequence:
- repeat:
until:
- condition: state
entity_id: input_select.12345
state: '2'
sequence:
- service: script.bottone_luci_taverna
data: {}
- conditions:
- condition: state
entity_id: input_select.luci
state: Sinistra
sequence:
- repeat:
until:
- condition: state
entity_id: input_select.12345
state: '3'
sequence:
- service: script.bottone_luci_taverna
data: {}
default: []
mode: single
The physical buttons in the room don’t actually fire the internal relay of the sonoff but move the “desired” input select to the next option
.
This is my attempt at writing an automation for the input select, It’s fired either when the “actual input select” status changes and when the status of the input boolean is changed. The problem is that the automation in this case fires itself.
The way this would work is if I was able to put a condition so that the part that change the “desired input select” only fires if the “actual” input select hasn’t been changed in a while but I am not sure how to do it
alias: AAA Generali taverna on/off
description: ''
trigger:
- platform: state
entity_id: input_select.12345
- platform: state
entity_id: input_boolean.on_off_generali_taverna
condition: []
action:
- choose:
- conditions:
- condition: state
entity_id: input_select.12345
state: ''
sequence:
- choose:
- conditions:
- condition: or
conditions:
- condition: state
entity_id: input_select.12345
state: '1'
- condition: state
entity_id: input_select.12345
state: '2'
- condition: state
entity_id: input_select.12345
state: '3'
sequence:
- service: input_boolean.turn_on
target:
entity_id: input_boolean.on_off_generali_taverna
- conditions:
- condition: state
entity_id: input_select.12345
state: '0'
sequence:
- service: input_boolean.turn_off
target:
entity_id: input_boolean.on_off_generali_taverna
default: []
- conditions: [ **See what I say above about this** ]
sequence:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.on_off_generali_taverna
state: 'on'
sequence:
- service: input_select.select_option
target:
entity_id: input_select.luci
data:
option: Acceso
- conditions:
- condition: state
entity_id: input_boolean.on_off_generali_taverna
state: 'off'
sequence:
- service: input_select.select_option
target:
entity_id: input_select.luci
data:
option: Spento
default: []
default: []
mode: single