Within the template editor this gives me the serialnumber of the first inverter, when i put this in the configuration file it gives me nothing…
After trying for day’s with this template i start to wonder if i get a json from the webserver through HA, is there a way to check if it’s really working?
Secondly how could i loop through all those inverters???
\
state_attr requires an entity_id string and an attribute string as arguments.
The first argument looks right, but the 2nd one doesn’t.
It’s either you want the attribute ‘serialnumber’, or ‘[serialnumber]’. Either way, you’ll need quotes around the 2nd parameter. Also, not sure what’s up with the quotes around the [‘0’]. Maybe it’s ok, but unless the entity is named “0”, just use a number for the index.
Hi Jim,
Thx for the fast reply.
I checked your , but it still gives me the same unavailable error so i really think i did something wrong with getting the file from the server. But have looked around and as far as i can find this should be the way to call the website for the json file.
To be sure i checked both your and mine value template line in the editor and both gave me the serialnumber i want but nothing in the sensor:-(
I f i only knew how to be sure it pulls down the json file i could continue with templating…
The value_json is only a property of the original sensor that grabbed it. Outside of that sensor, you can’t access the value_json.
Further, you’ll have to update your rest sensor to tell it how to parse that json.
You have 2 options here. 1) have the restful sensor just a dumb sensor that grabs ALL of the json and stores it in attributes for other template sensors to parse.
Create a rest sensor for each entry in the json.
I think this will work with #1. I’m not 100% sure how to do number 2.
If you want multiple rest sensors, it would look like this:
- platform: rest
name: solarpanel_1
resource: 'http://10.10.1.4/api/v1/production/inverters'
username: 'installer'
password: 'xxxxxxxxx'
authentication: 'digest'
value_template: "{{ value_json[0].lastReportWatts }}"
# Just store all values as an attribute. Sure, lastReportWatts will be duplicated, but oh well.
json_attributes_path: "$.[0]"
json_attributes:
- serialNumber
- lastReportDate
- devType
- maxReportWatts
# This one will get the 2nd in the json
- platform: rest
name: solarpanel_2
resource: 'http://10.10.1.4/api/v1/production/inverters'
username: 'installer'
password: 'xxxxxxxxx'
authentication: 'digest'
value_template: "{{ value_json[1].lastReportWatts }}"
# Just store all values as an attribute. Sure, lastReportWatts will be duplicated, but oh well.
json_attributes_path: "$.[1]"
json_attributes:
- serialNumber
- lastReportDate
- devType
- maxReportWatts