I’m struggling with an automation to update my input select based on switch states.
I’ve been creating an input select to control my ventilation system (Low/Medium/High).
Low is basically default, when I want to go to Medium, I toggle Fibaro switch 1, to go to High, I toggle Fibaro switch 2 and turn of switch 1 if turned on prior to that. This is handled by scripts and I’ve managed to this within one automation.
Both Fibaro switches are also connected to a legacy switch. Everything works but now I would like to update the input select when the system is switched with the legacy switch.
I think I can do this with service templates but how?
Basically if switch 1 is turned on → input select to Medium and if switch 2 is turned on → input select to High. I can do this with 4 different automations but would like to understand how this works with a single one.
So based on your example @septillion I would also be able to create one automation to trigger the ventilation based on humidity measured on one of my sensors right?
Option 1, if humidity is above 75% trigger the input select to High, Option 2, if humidity becomes lower than 65% trigger the input select to Medium etc? Am I correct here?
No maybe I did not explain it correctly, I was able to create the automation using the service_template, however I learned by your post that this was deprecated and should be replaced with service. That is working now.
The original requirement was to change the input select based on switch states. So if switch A is turned on and switch B is turned off, change the input select to Medium. If switch A is turned off and switch B is turned on, change the input select to High.
Both are working now, I’ve changed the automation for the input select to call scripts to your suggestion and that works fine and with the example Timo provided I’ve also managed to create an automation to change the state of the input select.
I would even put everything in a single automation and just dump the scripts. This would remove the need for a delay (the for:) by setting the mode to single.
And yeah, you could make a separate automation which will just set the input_select to the desired state. Although I would not use fixed humidity for that. On rainy summer day you might run into trouble that way.
Even better! Just implemented this and helps a lot keeping the automations down to a minimum.
You would suggest to use a trigger based on increase in humidity I guess? Instead of a fixed amount?
Would you happen to have an example for this as well?
I’m fairly new to automations, so trying to find my way while trying to keep the amount down to a minimum.
It does depend on what you try to do. If it’s the common bath room fan then I still like the use of a trend-sensor to trigger the start of “more ventilation”. If you save the current humidity when it triggers then you can stop the ventilation again when you drop below that value again (or maybe that value + few percent).
And what I’ve used for things that have states and you want to mix automatic control and manual control (override) is to make a second input_select with the same options as the states + the option “Automatic”. And you only allow the automatic control to run when it’s set to “Automatic” and just duplicate (with an automation) the other states to the first input_select. That way you have an input_select to use from the frontend (set the operation mode) and an input_select which contains the actual state of the device.
And yeah, with templates you can probably write things shorter but I like the UI friendly approach.
alias: Algemeen Balansventilatie
description: ''
trigger:
- platform: state
entity_id: input_select.balansventilatie
id: balansventilatie_input_select_low
to: Low
- platform: state
entity_id: input_select.balansventilatie
id: balansventilatie_input_select_medium
to: Medium
- platform: state
entity_id: input_select.balansventilatie
id: balansventilatie_input_select_high
to: High
- platform: state
id: balansventilatie_status_low
entity_id: sensor.keuken_switch_balansventilatie
for:
hours: 0
minutes: 0
seconds: 2
to: Low
- platform: state
id: balansventilatie_status_medium
entity_id: sensor.keuken_switch_balansventilatie
for:
hours: 0
minutes: 0
seconds: 2
to: Medium
- platform: state
id: balansventilatie_status_high
entity_id: sensor.keuken_switch_balansventilatie
for:
hours: 0
minutes: 0
seconds: 2
to: High
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: balansventilatie_input_select_low
- condition: not
conditions:
- condition: state
entity_id: sensor.keuken_switch_balansventilatie
state: Low
sequence:
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.balansventilatie_medium
- switch.balansventilatie_high
- conditions:
- condition: trigger
id: balansventilatie_input_select_medium
- condition: not
conditions:
- condition: state
entity_id: sensor.keuken_switch_balansventilatie
state: Medium
sequence:
- choose:
- conditions:
- condition: state
entity_id: switch.balansventilatie_high
state: 'on'
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.balansventilatie_high
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: switch.turn_on
data: {}
target:
entity_id: switch.balansventilatie_medium
default:
- service: switch.turn_on
data: {}
target:
entity_id: switch.balansventilatie_medium
- conditions:
- condition: trigger
id: balansventilatie_input_select_high
- condition: not
conditions:
- condition: state
entity_id: sensor.keuken_switch_balansventilatie
state: High
sequence:
- choose:
- conditions:
- condition: state
entity_id: switch.balansventilatie_medium
state: 'on'
sequence:
- service: switch.turn_off
data: {}
target:
entity_id: switch.balansventilatie_medium
- delay:
hours: 0
minutes: 0
seconds: 1
milliseconds: 0
- service: switch.turn_on
data: {}
target:
entity_id: switch.balansventilatie_high
default:
- service: switch.turn_on
data: {}
target:
entity_id: switch.balansventilatie_high
- conditions:
- condition: trigger
id: balansventilatie_status_low
- condition: not
conditions:
- condition: state
entity_id: input_select.balansventilatie
state: Low
sequence:
- service: input_select.select_option
data:
option: Low
target:
entity_id: input_select.balansventilatie
- conditions:
- condition: trigger
id: balansventilatie_status_medium
- condition: not
conditions:
- condition: state
entity_id: input_select.balansventilatie
state: Medium
sequence:
- service: input_select.select_option
data:
option: Medium
target:
entity_id: input_select.balansventilatie
- conditions:
- condition: trigger
id: balansventilatie_status_high
- condition: not
conditions:
- condition: state
entity_id: input_select.balansventilatie
state: High
sequence:
- service: input_select.select_option
data:
option: High
target:
entity_id: input_select.balansventilatie
mode: parallel
max: 10
This has three advantages:
There is an additional safety feature: both switches cannot be on at the same time. Some ventilation systems could become damaged if the two switches are on at the same time. By adding a second delay between “switching the switches”, you prevent any situation in which both would be on for a few miliseconds. I’ve incorporated similar additional safety within my Shelly 2.5 switch as well (independent of home assistant). By having all this in place, you are replicating what the original turning switch is doing:
The physical design of the switch prevents that both switches are on at the same time, because the middle position (Low) is turning both switches off. So you are always first forcing a complete off, before turning anything on.
2. I’ve added an additional condition so that any change in the input select will only try to change the state of the ventilation, if the ventilation state is different as compared to the input select. It’s a small addition, and from functional point of view nothing will change. Just a small improvement so it will check this upfront, instead of afterwards. This also makes debugging easier.
To do this, i’ve created a template sensor in configuration.yaml
sensor:
- platform: template
opbergruimte_balansventilatie:
friendly_name: 'Opbergruimte Balansventilatie'
unique_id: 598d8eca-6637-47bc-b174-5802f613248f
value_template: >
{% if is_state('switch.balansventilatie_medium', 'off') and is_state('switch.balansventilatie_high', 'off') %}
Low
{% elif is_state('switch.balansventilatie_medium', 'on') and is_state('switch.balansventilatie_high', 'off') %}
Medium
{% elif is_state('switch.balansventilatie_medium', 'off') and is_state('switch.balansventilatie_high', 'on') %}
High
{% else %}
Error
{% endif %}
Debugging the automation becomes easy, everything is in one overview. This is also why the template sensor becomes handy: more debug info, because you see the current state of the ventilation.