Restful sensor doesn't show values

I’m trying to get connect to my EasyServ (heatpump). They have a RestAPI (which works fine, see picture)

I have added information given by the company in configuration.yaml:

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Easyserv värmepump REST API

sensor:

  - platform: rest

    resource: https://easyserv.local:8080/api/metrics?authkey=[...]

    verify_ssl: false

    name: heatpump

    json_attributes:

      - HotwaterTemp1

      - HotwaterTemp2

      - IndoorTemp

      - OutdoorTemp

      - RadiatorForwardTemp

      - RadiatorReturnTemp

      - HeatCarrierInTemp

      - HeatCarrierOutTemp

      - BrineInTemp

      - BrineOutTemp

      - HotGasTemp

      - CompressorState

      - ColdCircuitPumpState

      - HeatCircuitPumpState

      - RadiatorPumpState

      - AddHeat2State

      - AddHeat1State

      - SwitchValve1State

      - HeatingSetpointTemp

      - HotwaterSetpointTemp

      - AddHeatLevelPercent

      - SumAlarm

    value_template: '{{ value_json.CompressorState }}'

  - platform: template
  
    sensors:

      hotwater_temp:

        friendly_name: 'Varmvatten'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.HotwaterTemp1 }}'

      outdoor_temp:

        friendly_name: "Utomhus-temp"

        unit_of_measurement: 'C'

        device_class: temperature

        value_template: '{{ states.sensor.heatpump.attributes.OutdoorTemp }}'

      radiator_forward:

        friendly_name: 'Framledning'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.RadiatorForwardTemp }}'

      radiator_return:

        friendly_name: 'Returledning'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.RadiatorReturnTemp }}'

      heatcarrier_in:

        friendly_name: 'Värmebärare in'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.HeatCarrierInTemp }}'

      heatcarrier_out:

        friendly_name: 'Värmebärare ut'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.HeatCarrierOutTemp }}'

      brine_in:

        friendly_name: 'Köldbärare in'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.BrineInTemp }}'

      brine_out:

        friendly_name: 'Köldbärare ut'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.BrineOutTemp }}'

      hotgas:

        friendly_name: 'Hetgas'

        unit_of_measurement: 'C'

        value_template: '{{ states.sensor.heatpump.attributes.HotGasTemp }}'

      compressor_state:

        friendly_name: "Kompressor"

        value_template: >-

          {% if states.sensor.heatpump.attributes.CompressorState > 0 %}

            På

          {% else %}

            Av

          {% endif %}

      switchvalve_state:

        friendly_name: "Växelventil"

        value_template: >-

          {% if states.sensor.heatpump.attributes.SwitchValve1State > 0 %}

            På

          {% else %}

            Av

          {% endif %}

      radiatorpump_state:

        friendly_name: "Radiatorpump"

        value_template: >-

          {% if states.sensor.heatpump.attributes.RadiatorPumpState > 0 %}

            På

          {% else %}

            Av

          {% endif %}

      coldcircuitpump_state:

        friendly_name: "Köldbärarpump"

        value_template: >-

          {% if states.sensor.heatpump.attributes.ColdCircuitPumpState > 0 %}

            På

          {% else %}

            Av

          {% endif %}

(With the correct authkey)

I can see the Integration, but no values

Log gives this error:

Logger: homeassistant.helpers.event
Source: helpers/template.py:400
First occurred: 10:36:48 (13 occurrences)
Last logged: 10:36:48

Error while processing template: Template("{{ states.sensor.heatpump.attributes.HotGasTemp }}")
Error while processing template: Template("{% if states.sensor.heatpump.attributes.CompressorState > 0 %} På {% else %} Av {% endif %}")
Error while processing template: Template("{% if states.sensor.heatpump.attributes.SwitchValve1State > 0 %} På {% else %} Av {% endif %}")
Error while processing template: Template("{% if states.sensor.heatpump.attributes.RadiatorPumpState > 0 %} På {% else %} Av {% endif %}")
Error while processing template: Template("{% if states.sensor.heatpump.attributes.ColdCircuitPumpState > 0 %} På {% else %} Av {% endif %}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 398, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1698, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 925, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.9/site-packages/jinja2/sandbox.py", line 326, in getattr
    value = getattr(obj, attribute)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1724, in _fail_with_undefined_error
    raise ex
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1715, in _fail_with_undefined_error
    return super()._fail_with_undefined_error(*args, **kwargs)
jinja2.exceptions.UndefinedError: 'None' has no attribute 'attributes'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 514, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 400, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'None' has no attribute 'attributes'

Anyone have an idea how to troubleshoot?

I don’t see these keys in the data you posted yet you have specified them as attributes in your rest sensor:

I got tired of visually searching after that (please dont post pictures of text, very hard to search).

Also please heed the warning here:

https://www.home-assistant.io/docs/configuration/templating/#states

Instead of this format:

value_template: '{{ states.sensor.heatpump.attributes.HotwaterTemp1 }}'

use this:

value_template: "{{ state_attr('sensor.heatpump', 'HotwaterTemp1') }}"

Also if you want to skip all those template sensors you can make all the sensors with one rest call by using the rest integration rather than the rest sensor platform.

e.g.

rest:
  - resource: https://easyserv.local:8080/api/metrics?authkey=[...]
    verify_ssl: false
    sensor:
      - name: Hot Water Temp
        value_template: "{{ value_json.HotwaterTemp1 }}"
        unit_of_measurement: "°C"
      - name: Indoor Temp
        value_template: "{{ value_json.IndoorTemp }}"
        unit_of_measurement: "°C"
      - name: Outdoor Temp
        value_template: "{{ value_json.OutdoorTemp }}"
        unit_of_measurement: "°C"
      - name: "Kompressor"
        value_template: >
          {% if value_json.CompressorState > 0 %}
            På
          {% else %}
            Av
          {% endif %}
      - name: etc...
1 Like

Hi,

Thank you for your help!

Unfortunately, when I try to add your suggested code to configuration.yaml I can’t see anything at all:

This is my configuration.yaml:


# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml


# Easyserv värmepump REST API
rest:
  - resource: https://easyserv.local:8080/api/metrics?authkey=[...AUTH...]
    verify_ssl: false
    sensor:
      - name: Hot Water Temp
        value_template: "{{ value_json.HotwaterTemp1 }}"
        unit_of_measurement: "°C"
      - name: Indoor Temp
        value_template: "{{ value_json.IndoorTemp }}"
        unit_of_measurement: "°C"
      - name: Outdoor Temp
        value_template: "{{ value_json.OutdoorTemp }}"
        unit_of_measurement: "°C"
      - name: "Kompressor"
        value_template: >
          {% if value_json.CompressorState > 0 %}
            På
          {% else %}
            Av
          {% endif %}

Sorry for posting image last time. Here are the RestAPI respond:

{"HotwaterTemp1": 49.5, "ColdCircuitPumpState": 1, "RadiatorForwardTemp": 38.2, "HotGasTemp": 50.400000000000006, "HeatingSetpointTemp": 33.0, "HeatCarrierInTemp": 26.1, "HeatCircuitPumpState": 1, "CompressorState": 1, "RadiatorPumpState": 1, "LowPressostat": 1, "BrineInTemp": 6.3000000000000012, "SumAlarm": 0, "IndoorTemp": -853.1, "AddHeatLevelPercent": 0.0, "HeatCarrierOutTemp": 38.6, "BrineOutTemp": 2.4000000000000003, "HotwaterSetpointTemp": 64.0, "OutdoorTemp": -0.9, "SwitchValve1State": 0, "HighPressostat": 1, "AirIntakeTemp": 0.0, "FanState": 0}

Go to developer tools / states, do you see a sensor.kompressor there?

Are there any related errors in your log?

1 Like