Reusing Helpers and Automations

I’ve switched from OpenHAB to Home Assistant and I’m really struggling with one problem.

I have quite a lot Homematic IP thermostats (HmIP-BWTH) that control my heating.

These thermostats have an entity “active_profile” which is a number an represents the heating mode that the thermostat uses.

I’m using 4 profiles:
1 => Normal
2 => Present Free
3 => Present Work
4 => Not Present

What I want now is controlling this heating mode with a dropdown.

So I created a Dropdown-Helper with the four states as options (Normal, Present Free, Present Work, Not Present).

And two automation. One automation that changes the dropdown when the entity changes and one automation that changes the entity when the dropdown changes.

So far this seems to work fine. The problem is, that I have 15 of these thermostats.

So with the concept I have now I would need to create 15 helpers and 30 automation.

Is this the right way to do it? Is there another was without creating all this helpers and automations? Is there maybe a way to reuse the helper any automation dynamically with different entities?

Post the YAML code for the Input Select helpers and automations you have created.

Input Select:

input_select:
  test_heating_state:
    name: Heizungs Modus
    options:
      - Normal
      - Anwesend Frei
	  - Abwesend
	  - Anwesend Arbeit
    icon: mdi:radiator

Entity to selector:

alias: Test
description: ""
trigger:
  - platform: state
    entity_id:
      - number.dg_buero_fussbodenheizung_active_profile
condition: []
action:
  - if:
      - condition: state
        entity_id: number.dg_buero_fussbodenheizung_active_profile
        state: "1.0"
    then:
      - service: input_select.select_option
        target:
          entity_id: input_select.test_heating_state
        data:
          option: Normal
  - if:
      - condition: state
        entity_id: number.dg_buero_fussbodenheizung_active_profile
        state: "2.0"
    then:
      - service: input_select.select_option
        target:
          entity_id: input_select.test_heating_state
        data:
          option: Anwesend Frei
  - if:
      - condition: state
        entity_id: number.dg_buero_fussbodenheizung_active_profile
        state: "3.0"
    then:
      - service: input_select.select_option
        target:
          entity_id: input_select.test_heating_state
        data:
          option: Abwesend
  - if:
      - condition: state
        entity_id: number.dg_buero_fussbodenheizung_active_profile
        state: "4.0"
    then:
      - service: input_select.select_option
        target:
          entity_id: input_select.test_heating_state
        data:
          option: Anwesend Arbeit
mode: single

Selector to entity:

alias: Test 2
description: ""
trigger:
  - platform: state
    entity_id:
      - input_select.test_heating_state
condition: []
action:
  - if:
      - condition: state
        entity_id: input_select.test_heating_state
        state: Normal
    then:
      - device_id: a141042e453a95aedccbe346ad3283af
        domain: number
        entity_id: ac3fcfc769527c7ee5f3f56a5cdd6513
        type: set_value
        value: 1
  - if:
      - condition: state
        entity_id: input_select.test_heating_state
        state: Anwesend Frei
    then:
      - device_id: a141042e453a95aedccbe346ad3283af
        domain: number
        entity_id: ac3fcfc769527c7ee5f3f56a5cdd6513
        type: set_value
        value: 2
  - if:
      - condition: state
        entity_id: input_select.test_heating_state
        state: Abwesend
    then:
      - device_id: a141042e453a95aedccbe346ad3283af
        domain: number
        entity_id: ac3fcfc769527c7ee5f3f56a5cdd6513
        type: set_value
        value: 3
  - if:
      - condition: state
        entity_id: input_select.test_heating_state
        state: Anwesend Arbeit
    then:
      - device_id: a141042e453a95aedccbe346ad3283af
        domain: number
        entity_id: ac3fcfc769527c7ee5f3f56a5cdd6513
        type: set_value
        value: 4
mode: single

This is one of the standard use cases for a Template Select.

There are other ways to accomplish your goal that use fewer entities, but they would have a different order of operations compared to what you are currently using.

1 Like

Thanks for the suggestion. If I understand this correctly I would have to create one of these „Template Select“ for each thermostat right?

Could I use this within a blueprint?

Yes, you would have one Select entity for each thermostat.

It is unclear what you are asking… Generally speaking, yes, Select entities can be used in Blueprints. Just make sure to use the appropriate service calls in your actions.

Whether or not a specific Blueprint has been configured to be able to use them is a different question.

There’s a way to do this using a single automation and two Input Selects that can handle all 15 number entities. However, you will have to decide if the way it operates meets your needs and expectations.

  1. The first Input Select contains a list of all your 15 number entities.

  2. The second Input Select contains a list of all 4 profiles (like what you already have with input_select.test_heating_state`).

An automation connects the operation of the two Input Selects. When you use the first Input Select to choose a number entity, the second Input Select changes to display the chosen number’s current value. If you then use the second Input Select to change the value, the automation sets the associated number to the new value.

This allows you to use very few resources to display and control each one of the 15 number entities.

Let me know if this interests you or it isn’t the way you want to display/control the 15 entities.

I thought I could manage it myself, but it’s not working correctly with the code I have now.

Entity to dropdown works fine, but dropdown to entity gives me an error:

“select/select_option. expected float for dictionary value @ data[‘value’]”

Can you tell me what I’m doing wrong?

  - select:
      - name: "DG_Beuro_Fussbodenheizung_State_Select"
        unique_id: dg_buero_fussbodenheizung_state_select
        state: >
          {% set opt = states('number.dg_buero_fussbodenheizung_active_profile') %}
          {% set mapper = {
            '1.0': 'Normal',
            '2.0': 'Anwesend Frei',
            '3.0': 'Abwesend',
            '4.0': 'Anwesend Arbeit'
          }%}
          {{ mapper.get(opt) }}
        options: "{{['Normal','Anwesend Frei','Abwesend','Anwesend Arbeit']}}"
        select_option:
          - service: number.set_value
            data:
              value: >
                {% set mapper = {
                  'Normal': '1.0',
                  'Anwesend Frei': '2.0',
                  'Abwesend': '3.0',
                  'Anwesend Arbeit': '4.0'
                }%}
                {{ mapper.get(opt) }}
            target:
              entity_id: number.dg_buero_fussbodenheizung_active_profile
        

Got it. Was a stupid copy and paste error:

  - select:
      - name: "DG_Beuro_Fussbodenheizung_State_Select"
        unique_id: dg_buero_fussbodenheizung_state_select
        state: >
          {% set opt = states('number.dg_buero_fussbodenheizung_active_profile') %}
          {% set mapper = {
            '1.0': 'Normal',
            '2.0': 'Anwesend Frei',
            '3.0': 'Abwesend',
            '4.0': 'Anwesend Arbeit'
          }%}
          {{ mapper.get(opt) }}
        options: "{{['Normal','Anwesend Frei','Abwesend','Anwesend Arbeit']}}"
        select_option:
          - service: number.set_value
            data:
              value: >
                {% set mapper = {
                  'Normal': '1.0',
                  'Anwesend Frei': '2.0',
                  'Abwesend': '3.0',
                  'Anwesend Arbeit': '4.0'
                }%}
                {{ mapper.get(option) }}
            target:
              entity_id: number.dg_buero_fussbodenheizung_active_profile
1 Like

Just one more question could the above code use some sort of entity-id pattern (e.g. “where enityId like ‘*_fussbodenheizung_active_profile’” or “where entity is in area xyz”).
I know it doesn’t make sense in this use case, but I need something similar for a switch, where I get and set the state for several light- and switch-entities (something like a dynamical switch/light group).

Is there a tutorial or documentation that goes deeper into stuff like this.