Nezz
December 7, 2022, 9:22pm
1
I have created a couple of scenes:
scene.livingroom_morning
scene.livingroom_evening
I created an input_select
to track which one was last activated:
input_select.living_room_scene:
options:
- scene.livingroom_morning
- scene.livingroom_evening
I’d like to sync these two. I set up an automation to change the scene with the input_select
changes:
alias: Living Room scene automation
description: ''
trigger:
- platform: state
entity_id:
- input_select.living_room_scene
condition: []
action:
- service: scene.turn_on
target:
entity_id: '{{ states(''input_select.living_room_scene'') }}'
metadata: {}
mode: single
This works great. I’d also like to sync scene activations to update the input select (it should not create a recursion). I tried creating this automation but it doesn’t work:
alias: Living Room scene to switch
description: ''
trigger:
- platform: event
event_type: call_service
event_data:
domain: scene
service: turn_on
condition: []
action:
- service: input_select.select_option
target:
entity_id: input_select.living_room_scene
data:
option: '{{ trigger.event.data.service_data.entity_id }}'
mode: single
According to the logbook this runs without errors but the input_select is not changed. A few times it worked however:
Any idea what might be going on?
Bonus:
Can I run this conditionally only for scenes that start with scenes.livingroom
?
Can I avoid this automation triggering the scene switch again? (when it works)
PS: I know I could add a manual input_select
set to each scene, but I want to automate this instead.
Nezz
December 7, 2022, 9:42pm
2
It seems that the issue is that sometimes (but not always) the entity_id
is a string, but usually it’s an array.
pedolsky
(Pedolsky)
December 8, 2022, 6:01am
3
Shouldn’t this be input_select.set_options
?
Nezz
December 8, 2022, 7:58am
4
That would change the list of selectable options. select_option
is correct.
pedolsky
(Pedolsky)
December 8, 2022, 8:07am
5
But this is a loop. Automation 2 triggers automation 1.
Nezz
December 8, 2022, 9:04am
6
Yes, but automation 1 is only triggered when the input_select
changes value - if it’s set to the same value it was it will not happen.
pedolsky
(Pedolsky)
December 8, 2022, 3:46pm
7
Anyway, I can only suggest to look at the automation trace. Tested your second automation and it’s running flawlessly
To answer your first bonus question: You can limit the execution by using the following condition:
condition:
- condition: template
value_template: |
{% set trigger = trigger.event.data.service_data.entity_id %}
{{ trigger is search('livingroom_morning|livingroom_evening') }}
Nezz
December 8, 2022, 3:49pm
8
Yeah it breaks when invoked from certain places. In the end it’s this old “feature”:
opened 09:02AM - 11 Jan 20 UTC
closed 05:30PM - 14 Jan 20 UTC
integration: scene
<!-- READ THIS FIRST:
- If you need additional help with this template please r… efer to https://www.home-assistant.io/help/reporting_issues/
- Make sure you are running the latest version of Home Assistant before reporting an issue: https://github.com/home-assistant/home-assistant/releases
- Frontend issues should be submitted to the home-assistant-polymer repository: https://github.com/home-assistant/home-assistant-polymer/issues
- iOS issues should be submitted to the home-assistant-iOS repository: https://github.com/home-assistant/home-assistant-iOS/issues
- Do not report issues for integrations if you are using a custom integration: files in <config-dir>/custom_components
- This is for bugs only. Feature and enhancement requests should go in our community forum: https://community.home-assistant.io/c/feature-requests
- Provide as many details as possible. Paste logs, configuration sample and code into the backticks. Do not delete any text from this template!
-->
**Home Assistant release with the issue:**
0.103.6
**Last working Home Assistant release (if known):**
**Operating environment (Hass.io/Docker/Windows/etc.):**
Hassio on RPi 64bit
**Integration:**
https://www.home-assistant.io/integrations/scene/
**Description of problem:**
The formatting of the trigger event-data is different, when you turn on a scene through lovelace tap_action and calling the service "scene.turn_on" from an automation.
Case 1: Lovelace
`<Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=scene.home>`
Case 2: Automation-trigger
`<Event call_service[L]: domain=scene, service=turn_on, service_data=entity_id=['scene.home']>`
Notice the encasing of the entity_id
**Problem-relevant `configuration.yaml` entries and (fill out even if it seems unimportant):**
Case 1: Lovelace
```
tap_action:
action: call-service
service: scene.turn_on
service_data:
entity_id: scene.morning
```
Case 2: Automation-trigger:
```
action:
- service: scene.turn_on
entity_id: scene.morning
```
Code using the eventdata:
```
- id: home_scene_change
alias: home_scene_change
trigger:
- event_data:
domain: scene
service: turn_on
event_type: call_service
platform: event
action:
- service: script.notify_debug
data_template:
title: zwerg
message: "{{ trigger.event }}"
- service: input_text.set_value
data_template:
entity_id: input_text.home_state_scenes
value: "{{trigger.event.as_dict()['data']['service_data']['entity_id']}}"
- service: script.sys_writelog
data_template:
name: "{{trigger.event.as_dict()['data']['service_data']['entity_id']}}"
```
**Traceback (if applicable):**
```
```
**Additional information:**
As for the condition, I ended up going with this one liner:
{{ 'living_room' in trigger.event.data.service_data.entity_id }}
123
(Taras)
December 8, 2022, 4:07pm
9
FWIW, the second automation can be eliminated if you constrain your other automations/scripts to set the desired scene exclusively via the input_select and not directly via a scene.turn_on
service call.
Nezz
December 8, 2022, 4:08pm
10
I’m thinking about going the other direction now where everything is done via turning on scenes.
123
(Taras)
December 8, 2022, 4:11pm
11
OK. What was the original requirement for using an Input Select to choose a scene? Is that requirement no longer needed?