I’m fairly new to text-configurable part of HA. So far I’ve been mainly doing things through GUI, but now I’d like to take a step onwards.
I’ve sucessfully implemented a way for HA to recognize my Webex call state and I’ve created automations which turn on or off a Hue light, based on if I’m in a call or not.
The only thing is, that Webex has three “active” and two “non-active” states that apply to me. So, based on what I know how to do now, I created a set of automations, each with another combination of states.
There is probably a very simple way to combine all those states together, right?
Below an example of my current automation. In there if Webex state changes from “active” to “call” the light turns on. Other possible pre-light state is “idle”. And other possible post-light states are “meeting” and “presenting”.
- id: '1616580730730'
alias: Webex Status - busy
description: Turn on hallway light, depending on Webex status
trigger:
- platform: state
entity_id: sensor.webex_status
from: active
to: call
condition: []
action:
- type: turn_on
device_id: 51561d5881cd11ebbac78f65d5043d11
entity_id: light.hallway_3
domain: light
brightness_pct: 100
mode: restart
I’ve got 6 automations configured currently. How could I get them down to two?
I think that you can make all this into one by using the choose type action. First make the trigger any change of state of the webex_status. Please see the sample below. Its not complete but I hope you get the idea. If anything, please do ask.
Your original automation used a State Trigger that monitored a specific state-change, namely:
from: active
to: call
If the from state of the state-change is important, then you should be aware that the State Trigger in sheminasalam’s suggestion isn’t constrained that way and you’ll need to check it in choose's conditions (using trigger.from_state.state and trigger.to_state.state).
If from state is not important then the suggested automation should work well for you.
OK, I replaced my existing automations with your example and added missing states.
Unfortunately now I receive an error stating this:
Logger: homeassistant.components.homeassistant
Source: components/homeassistant/__init__.py:122
Integration: Home Assistant Core Integration (documentation, issues)
First occurred: 6:10:19 PM (4 occurrences)
Last logged: 6:16:16 PM
Error loading /config/configuration.yaml: while parsing a block collection in "/config/automations.yaml", line 1, column 1 expected <block end>, but found '?' in "/config/automations.yaml", line 58, column 1
Line 58 is where the “condition: [ ]” code is.
Since the line seems irrelevant I tried to simply remove it, but the error actually repeats, again on line 58, which is now, of course next line in the code.
OK, that did the trick. It took me extra time, to see why the light turned on immediately, while I was not on a call.
Once I fixed that, everything works, like it’s supposed to.
I see that indents were all that was wrong. I have to check and see if I can learn how to position them properly on my own.
Thanks a lot, kind sir. I’m in your debt. And I think you put me on my way to optimize the first two automations into one as well
Yes, thanks. That was the problem that I was referring to in previous reply, when the light came on immediately
Status “active” in WebEx actually means that you’re active at your PC but not on call or in meeting. So that’s actually when the light should be off. I changed this and now it’s working exactly how it’s supposed to.
If the light should be turned on only when the sensor’s state is call or presenting, and off for any other state (idle or active) then it can be done like this:
- id: '1616494858208'
alias: Webex Status Vlado
description: Turn hallway light on or off, depending on Vlado's Webex status
trigger:
- platform: state
entity_id: sensor.vlado_webex_status
condition: []
action:
- service: "light.turn_{{ 'on' if trigger.to_state.state in ['call', 'presenting'] else 'off' }}"
entity_id: light.hodnik_3_kabinet