Get visibility on scenes triggered

Hi all,

tl;dr: I am trying to change the value of an input_text from a scene. I am trying to do this, so I can register an event change into custom:home-feed-card. When I do so, I get a “reproduce_state” error. Any hints on workarounds?

Context
I am using a “custom:home-feed-card” to see all the state changes at my home. Unfortunately, the card does not work well with scripts, automations and scenes.

My workaround was to create an input_text. The script and/or automation would change the value and that would then be registered on the card. Example:

- id: auto_turn_on_lights_living_room
  alias: 'Auto: Turn on living room lights at night'
  trigger:
    - platform: sun
      event: sunset
      offset: '-00:30:00'
  action:
    - service: script.turn_on
      entity_id: script.light_daily_light
    - service: input_text.set_value
      data_template:
        entity_id: input_text.automation_run
        value: 'Turn on living room lights at night'

When this happens, input_text changes, and I get a record on my home feed card with the name of the script/automation that was run and the time.

The error message
Now, while this works in automations and scripts, scenes do not have capabilities for calling services. Hence, I was trying to simply change the “value” field like this:

- name: event_easter
  entities:
    group.living_room_lights_except_entrance:
      state: on
      brightness_pct: 80
      rgb_color: [239, 184, 77]
    input_text.scene_run:
      value: 'Event Easter'

When I do that, I get this error:
reproduce_state: Unable to reproduce state <state input_text.scene_run=None; value=Event Easter @ 2019-08-01T22:08:41.327347+08:00> (2)

Troubleshooting / Hypothesis
I have also tried with text and state. The former would simply replace “value” with “text” on the error (not sure why I tried text anyway as it’s not an attribute), the latter would just have the = for the state like: reproduce_state: Unable to reproduce state <state input_text.scene_run=Event Easter @ 2019-08-01T22:08:41.327347+08:00> (2). Aka: same error, just showing the attributes I am setting.

My first thought was that input_text does not have a set state method, or maybe one to read it (since it is called “reproduce_state”. The error line seems to be indicating something along these lines. It doesn’t seem to find the service to do so. My confusion is that from the States tab on Hassio, I can actually see the current state and set the state to any random value. Hence, I am unsure what the underlying cause really is.

Solutions / Workarounds

My only thought at the moment is to create a script that would change the value. However, as far as I know, scenes cannot pass data/value parameters to the script. Hence, I cannot have a templated script where one script would change the value and the name of the scene will be passed to be set as the value (“Event Easter” on the previous example).

Creating one script per scene is also not very viable as I have somewhere between 20-40 scenes.

Any ideas or workarounds?

Thank you!

I’ve opened a bug report for now; although I am unsure whether it is expected and just not supported. Any insights appreciated. Thanks!

Scenes can only turn on things. Input_text’s don’t have a turn_on service. That PR will go nowhere.

Now for a solution, you could write an automation that looks for scene services and populates the input text.

- alias: Populate Input Text on Scene
  trigger:
    - platform: event
      event_type: call_service
      event_data:
        domain: scene
        service: turn_on
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.automation_run
        value: "{{ trigger.service_data.entity_id.split('.')[-1].replace('_',' ').title() }}"

When a scene like scene.event_easter is executed, it will take the object_id event_easter and modify it. It will replace the _ with a space, then it will transform the name to have capitals for each word Event Easter. Then it will plop it into your input text.

1 Like

Hi @petro

Thanks a lot for your input.

I think that workaround should work. I wasn’t aware of call_service was one of the possible event types. Appreciated!

In retrospective, I could probably have used the same for scripts and maybe automations and would have been much cleaner than the current approach!

Thanks!

Scenes can only turn on things

Is that statement fully accurate?

I am able to change attributes too, like brightness_pct, rgb_color or effect. The state of elements and groups can also be changed, although in that case I usually do use on/off.

Example:

- name: living_party_lights
  entities:
    light.living_entrance: off
    group.living_room_tv_lights:
      state: on
      brightness_pct: 50
      rgb_color: [1, 108, 194]
    group.living_room_kitchen_rack_lights:
      state: on
      brightness_pct: 50
      effect: 'colorloop'
    group.living_room_main_lights:
      state: on
      brightness_pct: 50
      effect: 'colorloop'

they can only turn things on or off. The other attributes are apart of the turn on service. So the statement is only partially accurate because I didn’t mention ‘off’.

Actually, yeah, those attributes are on the turn_on service for light. That’d explain. Thanks again!

I managed to get his work, but with minor changes to the service_data value.
It should be trigger.event.data.service_data instead of trigger.service_data.

Working solution:

################################################################################
# Automation: Scenes.
################################################################################

- alias: Populate Input Text on Scene
  trigger:
    - platform: event
      event_type: call_service
      event_data:
        domain: scene
        service: turn_on
  action:
    - service: input_text.set_value
      data_template:
        entity_id: input_text.automation_run
        value: '{{ trigger.event.data.service_data.entity_id.split(".")[-1].replace("_", " ").title() }}'

Thanks!

1 Like