Entity with variable number of attributes

Hello!
I’m just starting my adventure with HA and just learning the basic stuff.
Here’s the problem I need help with. I have a device that exposes REST API. I can get certain values with RESTful sensor and also change the device’s state with RESTful command. However, this is the thing.
The device has configurable profiles, each profile sets the certain number of parameters. A user can create as many profiles as they want. I can get the list of existing profiles with the REST, here’s the response.

"thermostat_ext_modes_config":{
	"0":{"active":true,"name":"Economy","schedule_number":null,"zone_sensors":{"1":1,"0":null},"zone_temp":{"1":15.0,"0":false}},
	"1":{"active":true,"name":"Comfort","schedule_number":null,"zone_sensors":{"1":1,"0":null},"zone_temp":{"1":23.0,"0":65.0}},
	"2":{"active":true,"name":"Schedule","schedule_number":null,"zone_sensors":{"1":0},"zone_temp":{"1":25.0},"hidden":true},
	"3":{"active":true,"name":"Warmer","schedule_number":null,"zone_sensors":{"1":0,"0":null},"zone_temp":{"1":25.0,"0":65.0},"hidden":false},
	"4":{"active":true,"name":"Summer","zone_sensors":{"0":null,"1":null},"zone_temp":{"0":65.0,"1":false},"schedule_number":null,"hidden":false},
}

And it also has a parameter which indicates the ID of the current active profile:

"thermostat_ext_mode":0,

I actually can activate the desired profile with REST command, but it’s static. Meaning I should already know the list of profiles and which ID is assigned to each profile.

What I’d like:

  • have some card which lists all the available profiles
  • switch between them clicking a button of a desired profile

Any idea how this could be implemented?

Here’s my current configuration:

sensor:
  - platform: rest
    resource: https://zont-online.ru/api/devices
    name: zont
    method: POST
    timeout: 50
    scan_interval: 60
    force_update: true
    headers:
      X-ZONT-Client: !secret x_zont_client
      X-ZONT-Token: !secret x_zont_token
      Content-Type: application/json
    payload: '{"load_io": true}'
    picture: https://zont-online.ru/wp-content/themes/zont/images/logo-footer.svg
    icon: https://zont-online.ru/wp-content/themes/zont/images/thumb_icon/gsm.svg
    value_template: '{{ value_json.ok }}'
    json_attributes_path: "$.[0]"
    json_attributes:
      - thermometers
      - io
      - thermostat_ext_mode
      - thermostat_ext_modes_config
      - id

rest_command:
  zont_set_comfort:
    url: https://zont-online.ru/api/update_device
    method: POST
    headers:
      X-ZONT-Client: !secret x_zont_client
      X-ZONT-Token: !secret x_zont_token
      Content-Type: application/json
    payload: '{"device_id": xxxxx,"thermostat_ext_mode": 1 }'

template:
  - sensor:
    # Thermostat mode
    - name: "Curent mode"
      state: > 
        {% if state_attr('sensor.zont', 'thermostat_ext_mode') is not none %}
            {% set mode = '' ~ state_attr('sensor.zont', 'thermostat_ext_mode') ~ '' %}
            {{ state_attr('sensor.zont', 'thermostat_ext_modes_config')[mode].name }}
        {% endif %}

OK, I managed to complete almost evetything. I took input_select as a solution. The only thing remaining is how to set the varailbe options for the input_select? I see there is set_options service, however I didn’t find a way to set dynamic options for it. Does anyone have any recommendation?

Make a template select instead of using an input_select. It’s designed to handle this. If you need help with that, post the entity_id and it’s attributes here and I’ll help.

Hi Petro!
Thanks for offering help, I definitely need it. However, I don’t really understand which entity_id and attributes are required… Can you please clarify?

Hi again
Thanks a lot for the hint! Though the template select documentation is very poor, I managed to find an example and achieved my goal. Thanks!