Which non json text sensor type to use for http command which returns 18 values?

I am wanting to just collect data from a HVAC unit, the only data it will return is:


It is a bit clunky so I’d prefer to hit it up with one command, grab the values I want, and store/monitor them.

So back to the question - can someone please help me determine:

  1. which sensor type
  2. a good example so I can hack my way through it


There might be a better way I’m not thinking of, but I’d do this. First, create whatever sensor is necessary to get that string into its state. (You didn’t say much about how you can obtain that string, so I assume you already have that part covered. If not, please provide more detail.) Let’s call this sensor sensor.hvac_raw, such that {{ states('sensor.hvac_raw') }} would return that string.

Then you can create a Template Sensor whose state is whatever value is most important (e.g., roomtemp), and which has attributes for other values you care about. Maybe something like:

  - platform: template
        friendly_name: HVAC
        unit_of_measurement: '°C'
        value_template: >
          {{ states('sensor.hvac_raw')|regex_findall_index('roomtemp=([0-9.]+)') }}
          op_mode: >
            {{ states('sensor.hvac_raw')|regex_findall_index('opmode=([0-9.]+)') }}
          set_temp: >
            {{ states('sensor.hvac_raw')|regex_findall_index('settemp=([0-9.]+)') }}
          fan_speed: >
            {{ states('sensor.hvac_raw')|regex_findall_index('fanspeed=([0-9.]+)') }}
1 Like

The following template converts the string into a JSON dictionary object:

{% set x = ('{"' ~ value.replace('=','":"').replace('&','"&"').split('&') | join(',') ~ '"}') | from_json  %}

It lets you easily access each item in the dictionary. However, to my knowledge, the only kind of sensor that can efficiently create attributes from that dictionary is MQTT Sensor using its json_attributes_template. It would look something like this:

  json_attributes_template: >-
    {% set x = ('{"' ~ value.replace('=','":"').replace('&','"&"').split('&') | join(',') ~ '"}') | from_json  %}

In a Template Sensor, each attribute is handled by a separate template option (see Phil’s example), so the string-to-object conversion would have to be repeated in each option … which is inefficient.

As for a Restful Sensor, itsjson_attributes option is unable to use a template so it cannot support this approach.

1 Like