Variable Pointer to Entity

I would like to target a different entity with the same set of actions, depending on time of year (cooling in Summer, heating in Winter). Is there a way for me to define a variable/pointer called seasonal_thermostat, that can point to different entities?

For example, instead of putting:

call_service: climate.turn_off
  - climate.office_heat
  - climate.office_ac

I would call

call_service: climate.turn_off
entity_id: seasonal_thermostat

where in summer, seasonal_thermostat == climate.office_ac, and in winter, == climate.office_heat.

You can use Templating to achieve your goal. Where are you planning on having the logic for the value of seasonal_thermostat come from?

I’m planning to have use an input_select to condition on, so the logic is if input_select.cooling _mode == "Cooling" then seasonal_thermostat == climate.office_ac.

Would you be able to provide a sample template for this? I’m generally comfortable with them, but unsure of how to implement them upstream of my automation (I don’t want to input the template each time I write an automation). Thanks!

I think the most concise method is to set up the templated service call in a script…

alias: Seasonal Climate On
description: ""
  - service: climate.turn_on
      entity_id: |
        {% set mode = states('input_select.cooling_mode') %}
        {{ "climate.office_ac" if mode == "Cooling" else "climate.office_heat" }}

then you can call the script as a service in automations or button actions, etc.

alias: Some automation
description: ""
  - service: script.seasonal_climate_on
    data: []

With the recently introduced Template Macros it is possible to have the entity ID available without an independent script, but you would still need to to call the climate.turn_on service with a templated target, so it wouldn’t be any more concise and it wouldn’t be usable in core dashboard card actions.

1 Like