I am trying automate a change of scene from “away” variant to “home” variant.
I want to do this by using a text_input as argumanet in a scene.turn_on. It is called “input_text.active_scene”, and I just want to add “_away” to the input_text and use it as argument in scene.turn_on.
And I want to do the opposite when going from away to home.
Simply remove the last 5 characters in “input_text.active_scene” (remove “_away”) and use the result as a argument in scene.turn_on.
I am using the inut_text in order to show the currect active scene in the front end as well, and it has the same name as the scene in the code. My thing was to reuse that in this automation.
WoW, thanks! I would never had solved this on my own. I am just a happy and stubborn amatuer.
If I also would like to update my input_text with the new value from {{ scen }} in the same automation, would that be possible with somethibng like this as a second serivce in the automation?
- service: input_text.set_value
entity_id: input_text.active_scene
data_template:
value: >-
{% set scene = states('input_text.active_scene') %}
{% if scene.endswith('_away') or scene.endswith('_home') %}
{% set scene = scene[:-5] %}
{% endif %}
{% if trigger.to_state.state == 'off' %}
{{ scene }}
{% else %}
{{ scene }}_away
{% endif %}
Yea, but in a very bad way.
I update it after each setting of a new scene, can probably de done better…
Each automation for setting of new scene ends with…
I will not post all, but one should be enought for you to see how bad my programming skills are : )
I have another boolean as well for vacation mode, that make all weekdays act like week ends. I also add a random delay when turning off lights in away mode.
- alias: "Turn off all lights on week ends"
trigger:
platform: time
at: '02:00:00'
condition:
condition: or
conditions:
- condition: state
entity_id: 'binary_sensor.workday_today'
state: 'off'
- condition: state
entity_id: input_boolean.vacation_mode
state: 'on'
action:
- delay: >
{% if is_state('input_boolean.away_mode', 'off') %}
00:00:00
{% else %}
{{ range(1*60,20*60+1)|random|timestamp_custom("%H:%M:%S",False) }}
{% endif %}
- service: scene.turn_on
data_template:
entity_id: >-
{% if is_state('input_boolean.away_mode', 'on') %}
scene.house_nights_away
{% else %}
scene.house_nights
{% endif %}
- service: input_text.set_value
entity_id: input_text.active_scene
data_template:
value: >-
{% if is_state('input_boolean.away_mode', 'on') %}
scene.house_nights_away
{% else %}
scene.house_nights
{% endif %}