I have a specific entity that is repeated, as either a trigger or a condition, in a number of automations. From time to time that integration goes rogue on me and then I need to updale all those automations.
I would like to create a variable so that, instead of updating all these automations, I only need to update the variable.
Can anyone put me in the right direction ?
Hi @EndUser
Generally variables are provided as Helpers.
Can you give a concrete code example of where a variable would be used in your automation.
Thanks. I looked at Helpers, before asking for ideas, and tied the button helper but that did not seem to work.
In the automations I would have something like:
trigger:
- platform: time
at: "05:55:00"
condition:
- condition: state
entity_id: calendar.18_trips
state: "off"
action:
- if:
- condition: or
conditions:
- condition: state
entity_id: binary_sensor.calendar_xyz_in_effect_2
state: "off"
then:
I would want a variable that represents " binary_sensor.calendar_xyz_in_effect_2 " in the automations
I think you could create a helper called,say,
input_text.my_calendar_name
You can set this to hold the name of your desired calendar entity.
Then use it in a template condition within your automation like this:
condition: template
value_template: "{{ states(input_text.my_calendar_name) == 'off' }}"
I’ve not tested this.
thanks. I will look into this.
I am not very good at editing Yaml and have not mastered (understood) Templates yet.
Neither am I. On second thoughts I think it should be:
condition: template
value_template: "{{ states(states('input_text.my_calendar_name')) == 'off' }}"
Why not change the entity, and not the automations ?
if binary_sensor.calendar_xyz_in_effect
gets changed to binary_sensor.calendar_xyz_in_effect_2
, change it back to binary_sensor.calendar_xyz_in_effect
instead of changing all your automations.
I wish that woulkd work.
What happened yesterday was with the latest HA Core update the Integration became unresponsive. This has happened before and it gets resolved by removing and re-adding th integration from configuration.yaml (*).
Then the specific entity changes its name from binary_sensor.calendar_xyz_in_effect_2 to binary_sensor.calendar_xyz_in_effect_7 or any other number at the end. Then I have to make that change in every automation.
(*) that is about how much I understand of and can do with yaml
I have this so often with my Tapo custom integration. After each update, tapo_camera_ee6d_cell_motion_detection
is changed to tapo_camera_ee6d_cell_motion_detection_2
.
I just click on it, (cogwheel)
and in the field ‘entity_id’, I change it back to tapo_camera_ee6d_cell_motion_detection
And all automations work again
You’re creating a non standard configuration and more work to work around a problem.
Is strongly suggest you look into why the integration ‘goes rogue’ and fix that instead.
The kind of work you are trying to do is a bad habit and will lead you to bad places in the future. Imagine years of stacked workarounds. Instead understand why it’s doing that and prevent it.
Thanks. THAT is the solution !!!
I agree and I did reach out to the developer twice but no response, but @francisp 's suggestion works.
FWIW, this can help to automate the process of renaming entity_ids. The Spook custom integration provides a service call to rename an entity’s entity_id
.