Grouping REST sensor entities?

I have a solar hot water system which has a data-collection device, and I’ve figured out that that device has a rest API. Cool. I’ve set this up and it all works:

rest:
  - resource: http://192.168.1.80/dlx/download/live 
    scan_interval: 60
    sensor:
      - name: "Solar Hot Water Collector Top"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[0].raw_value }}"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
      - name: "Solar Hot Water Tank Bottom"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[1].raw_value }}"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
      - name: "Solar Hot Water Tank Top"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[2].raw_value }}"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
      - name: "Solar Hot Water Unknown Temperature Sensur"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[3].raw_value }}"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
      - name: "Solar Hot Water Pump Speed"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[4].raw_value }}"
        state_class: measurement
        #icon: "mdi:pump"
        unit_of_measurement: "%"
      - name: "Solar Hot Water Operating Hours"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[6].raw_value }}"
        state_class: total_increasing
        #icon: "mdi:clipboard-text-clock-outline"
        unit_of_measurement: "h"
      - name: "Solar Hot Water Heat Quantity"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[17].raw_value }}"
        state_class: total_increasing
        #icon: "mdi:solar-power"
        unit_of_measurement: "Wh"
    binary_sensor:
      - name: "Solar Hot Water Sensor 1 Defective"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[12].raw_value }}"
        device_class: problem
      - name: "Solar Hot Water Sensor 2 Defective"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[13].raw_value }}"
        device_class: problem
      - name: "Solar Hot Water Sensor 3 Defective"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[14].raw_value }}"
        device_class: problem
      - name: "Solar Hot Water Sensor 4 Defective"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[15].raw_value }}"
        device_class: problem

… took me a little while to figure out that value_json starts at the root, making json_attributes_path / json_attributes not very useful. (Unfortunately, the returned JSON is… kind of disorganized. It’s really meant to feed a website template, not to get useful values from. But it works!)

However, I would like to group all of these things together into a “Solar Hot Water” device. Is there a way to do that, without creating a complete integration?

You could have one of them as the state and the rest as attributes.
Is that what you are looking for?

Maybe! There’s not really a single overall value that is the state — maybe “is the pump going?” or “temperature at top of tank”. But I guess that could give me what I’m looking for. Do you have an example of how to do that with Rest entities?

Let me update my answer, having looked around a bit. I think really for this case, I do want a device with different entities (although maybe also some entities with different attributes). But, I can see cases where I’d want to have that for sure. How can I create attributes instead of independent entities?

I think you can do something like this:

rest:
  - resource: http://192.168.1.80/dlx/download/live 
    scan_interval: 60
    sensor:
      - name: "Solar Hot Water Collector Top"
        value_template: "{{ value_json.headersets[0].packets[0].field_values[0].raw_value }}"
        device_class: temperature
        state_class: measurement
        unit_of_measurement: "°C"
        json_attributes:
          - headersets[0].packets[0].field_values[1].raw_value
          - headersets[0].packets[0].field_values[2].raw_value

and so on.
But I’m not completely sure.

1 Like

Ahhh. That wasn’t working for me… but now it makes sense. This is why some of the examples have “Okay” as the value_template. I’ll try that and see if it works!

I believe the issue is that the fact that the attributes is directly to values, it probably needs to be key value pair.

I think this could work, but it’s not pretty.

        json_attributes:
          - headersets[0].packets[0].field_values
1 Like