Hi, I’m trying to set up 1 rest sensor to return a block of json, which I will then parse with multiple template sensors.
I could set this up with multiple rest sensors, and specify the information I want from the json as part of the value_template for each sensor, but I’m trying to do this with 1 sensor instead of 40+ as I don’t want to make loads of unnecessary API calls.
I’ve played around with the dev template tool, if I copy the json into a test block in the editor, then I can parse it with square brackets, but trying this from the sensor output with states.sensor doesn’t work (the json text looks the same when it’s retrieved from a sensor or pasted in, I’m guessing when it’s retrieved from a sensor that it’s treated as a string rather than as json though.)
Wondering if there’s something obvious which I’ve missed, or if anyone else has a workaround for this?
As I understand it, basically you want to do what BRUH’s multisensor is doing, no?
I do not know I you have ever heard of it, give it a look in his video and on the forums (there is a topic with +200 posts I think)
Thanks, but that doesn’t look relevant to what I was asking. It looks like it’s polling multiple sensors via mqtt.
I was asking about having 1 sensor (either restful or command line with curl) retrieve a block of json, and then multiple templates could parse that json.
I’m using a RESTful sensor to get data from my PV inverter API, but since they do put a 300 API call limit a day, i cannot make a single request for each value.
disclaimer : just diving into HA and python, so I’m still a noob, but as far as I understand, the rest sensor doesn’t submit any attributes with the rest of the json data which could be used to create other template sensor from the same result (feature request needed).
Since others are interested in polling a sensor once and keeping the JSON metadata as well, I will clean-up the code referenced by @nxd4n and will send a Push Request. Though I need to test JSON objects which are not flat (e.g. { obj: [ 'item1', 'item2' ] }
Hi,
Can you help me with this:
<template state sensor.dijnet_fogaz=32790.0; unpaidInvoices=[{‘provider’: ‘NKM Energia - földgáz’, ‘issuerId’: ‘FőGáz’, ‘invoiceNo’: ‘101903866191’, ‘issuanceDate’: ‘2020.05.25’, ‘invoiceAmount’: 32790.0, ‘deadline’: ‘2020.06.11’, ‘amount’: 32790.0}], unit_of_measurement=Ft, friendly_name=Dijnet (FőGáz), icon=mdi:currency-usd @ 2020-05-31T20:29:09.137437+02:00>
How can I parse for example the deadline?