Trying to get a RESTful sensor working

So I’m three days into Home Assistant and I’m probably trying the deep end too soon but here I go. I’m trying to get some PowerData from PowerHouse Dynamics eMonitor/SiteSage.

Here the fairly minimal config entry that I’ve come up with to see if I can get the systems to talk:

sensor:
  - platform: rest
    name: sub
    resource: http://192.168.125.85/status.xml
    json_attributes_path: "$.emonitor"
    json_attributes:
    - "hardware"
    - "channels"
    value_template: '{{ value_json["hardware"]["network"]["IP_address"] }}'

The log is showing:

2020-10-28 09:43:47 WARNING (SyncWorker_4) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON
2020-10-28 09:44:09 WARNING (SyncWorker_1) [urllib3.connectionpool] Connection pool is full, discarding connection: px1.tuyaus.com
2020-10-28 09:44:17 WARNING (SyncWorker_16) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON

The endpoint returns XML but my understanding is that it should be automagically converted to JSON

Here is a sample of what it returns, don’t mind the mismatch IP addresses on the targets. I have two of them and I grabbed the example out from the second one.

<?xml version="1.0" encoding="UTF-8"?>

<emonitor>
 <hardware>
  <serial_number>4041</serial_number>
  <TLA_number>950-000002</TLA_number>
  <TLA_revision>B</TLA_revision>
  <firmware_version>16513</firmware_version>
  <network>
   <MAC_address>0090C2DE0734</MAC_address>
   <IP_address>192.168.125.189</IP_address>
  </network>
 </hardware>

 <channels>

 

  <channel Number="1">
   <active>1</active>
   <label>Main Power</label>
   <CT_size>150</CT_size>
   <paired_with_channel>2</paired_with_channel>
   <input>1</input>
   <max_power>75</max_power>
   <avg_power>20</avg_power>
   <inst_power>13</inst_power>
  </channel>



  <channel Number="2">
   <active>1</active>
   <label>Main Power</label>
   <CT_size>150</CT_size>
   <paired_with_channel>1</paired_with_channel>
   <input>1</input>
   <max_power>126</max_power>
   <avg_power>57</avg_power>
   <inst_power>52</inst_power>
  </channel>



  <channel Number="3">
   <active>1</active>
   <label>Outback Master</label>
   <CT_size>50</CT_size>
   <paired_with_channel>4</paired_with_channel>
   <input>1</input>
   <max_power>1</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="4">
   <active>1</active>
   <label>Outback Master</label>
   <CT_size>50</CT_size>
   <paired_with_channel>3</paired_with_channel>
   <input>1</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="5">
   <active>1</active>
   <label>Outback Slave #1</label>
   <CT_size>50</CT_size>
   <paired_with_channel>6</paired_with_channel>
   <input>1</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="6">
   <active>1</active>
   <label>Outback Slave #1</label>
   <CT_size>50</CT_size>
   <paired_with_channel>5</paired_with_channel>
   <input>1</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="7">
   <active>1</active>
   <label>Entry E Right</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>1</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="8">
   <active>1</active>
   <label>Garage W/Entry E Lef</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>92</max_power>
   <avg_power>88</avg_power>
   <inst_power>88</inst_power>
  </channel>



  <channel Number="9">
   <active>1</active>
   <label>120V panel outlet</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>1</max_power>
   <avg_power>1</avg_power>
   <inst_power>1</inst_power>
  </channel>



  <channel Number="10">
   <active>1</active>
   <label>Pool Pump/Chlorinato</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>9</max_power>
   <avg_power>8</avg_power>
   <inst_power>8</inst_power>
  </channel>



  <channel Number="11">
   <active>1</active>
   <label>Oven/Microwave</label>
   <CT_size>50</CT_size>
   <paired_with_channel>12</paired_with_channel>
   <input>0</input>
   <max_power>16</max_power>
   <avg_power>14</avg_power>
   <inst_power>15</inst_power>
  </channel>



  <channel Number="12">
   <active>1</active>
   <label>Oven/Microwave</label>
   <CT_size>50</CT_size>
   <paired_with_channel>11</paired_with_channel>
   <input>0</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="13">
   <active>1</active>
   <label>Dryer Outlet</label>
   <CT_size>50</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>1</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="14">
   <active>1</active>
   <label>Outback Slave #2</label>
   <CT_size>50</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>1</input>
   <max_power>1</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="15">
   <active>1</active>
   <label>AV EVSE</label>
   <CT_size>50</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>5</max_power>
   <avg_power>3</avg_power>
   <inst_power>4</inst_power>
  </channel>



  <channel Number="16">
   <active>1</active>
   <label>JuiceBox EVSE</label>
   <CT_size>50</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>2</max_power>
   <avg_power>1</avg_power>
   <inst_power>2</inst_power>
  </channel>



  <channel Number="17">
   <active>1</active>
   <label>Pool Light</label>
   <CT_size>50</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>1</max_power>
   <avg_power>1</avg_power>
   <inst_power>1</inst_power>
  </channel>



  <channel Number="18">
   <active>1</active>
   <label>Heat Pump</label>
   <CT_size>50</CT_size>
   <paired_with_channel>19</paired_with_channel>
   <input>0</input>
   <max_power>14</max_power>
   <avg_power>12</avg_power>
   <inst_power>13</inst_power>
  </channel>



  <channel Number="19">
   <active>1</active>
   <label>Heat Pump</label>
   <CT_size>50</CT_size>
   <paired_with_channel>18</paired_with_channel>
   <input>0</input>
   <max_power>11</max_power>
   <avg_power>9</avg_power>
   <inst_power>9</inst_power>
  </channel>



  <channel Number="20">
   <active>1</active>
   <label>Main Disposal</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="21">
   <active>1</active>
   <label>Prep Disposal</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="22">
   <active>1</active>
   <label>Blink EVSE</label>
   <CT_size>50</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>1</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="23">
   <active>1</active>
   <label>L6-20</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>0</input>
   <max_power>0</max_power>
   <avg_power>0</avg_power>
   <inst_power>0</inst_power>
  </channel>



  <channel Number="24">
   <active>1</active>
   <label>Xantrex</label>
   <CT_size>20</CT_size>
   <paired_with_channel>0</paired_with_channel>
   <input>1</input>
   <max_power>5</max_power>
   <avg_power>3</avg_power>
   <inst_power>4</inst_power>
  </channel>



</channels>
</emonitor>

I think I made progress now I’m seeing:

homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.sub. State max length is 255 characters.

Am I really limited to 255 characters in the response from the server? Is this Reddit post still correct?

Yes but only in the state. The attributes can contain over 255.

ok, thanks. I’ve been reading just everything about the relevant content that I could. There is so much stuff I need to figure. It’s helpful even just knowing that I’m not likely in a blind alley.

I just found the template editor, that looks like will be tomorrow learning climbing.

I decided to back up and try to get another example from

working, specifically the openweather one. Currently cutting and pasting the example doesn’t even pass the basic sync checker on the File editor. It spits this out:

can not read a block mapping entry; a multiline key may not be an implicit key at line 20, column 32:
            entity_picture_template: '{{ "https://openweathermap.or ... 

I was able to get a different example to work earlier. I did upgrade to Home Assistant 0.117.0 yesterday.

With some help from the Facebook group I think I made some more progress in debugging the issue. It was suggested the the developer tools to explore what I’m getting. So here is the fragment in my configuration.yaml:

sensor:
  - platform: rest
    name: OWM_report
    json_attributes:
      - main
      - weather
    value_template: '{{ value_json["weather"][0]["description"].title() }}'
    resource: https://api.openweathermap.org/data/2.5/weather?zip=80302,us&APPID=XXXXredactedXXXX
  - platform: rest
    name: emain
    resource: http://192.168.125.189/status.xml
    json_attributes_path: "$.emonitor"
    scan_interval: 30
    value_template: 'OK'
    json_attributes:
      - "hardware"
      - "channels"

When I go into Developer Tools -> Templates and type

{{ states.sensor.owm_report.attributes}}

I get

{'main': {'temp': 282.56, 'feels_like': 278.83, 'temp_min': 276.48, 'temp_max': 287.15, 'pressure': 1027, 'humidity': 34}, 'weather': [{'id': 800, 'main': 'Clear', 'description': 'clear sky', 'icon': '01d'}], 'friendly_name': 'OWM_report'}

Which looks reasonable.

But when I enter

{{ states.sensor.emain.attributes}}

I only get

{'friendly_name': 'emain'}

Which seems to tell me that the entity is there but it has wasn’t able to get attributes out of the XML. That seems to align with the error log entry that I’m seeing “2020-10-31 17:01:38 WARNING (MainThread) [homeassistant.components.rest.sensor] REST result could not be parsed as JSON”

The XML output when I paste into online XML to JSON converter seems sane (to the extent that I can tell). I previously had posted a sample up this thread.

I’m trying to find the example on how to turn up the debug level for the relevant part. I had it one point but I can’t find it at the moment.