I’m a little bit lost in the templating mechanism, apologies if it seems obvious for you…
Despite the documentation I found, I can’t understand how to avoid doing X calls for my X sensors by using template for doing only one. If I got it well, I’m supposed to retrieve the whole JSON value in one time and then use templates for mapping portion of it?
Have a look at the rest sensor’s json_attributes. That will allow you to make one rest call to fetch all data, store the details in attributes and then define one template sensor per attribute.
Thanks for the answer! I already looked at json_attributes and I just tried again, but I’m not sure it can do what I want, still trying, but without any success. How to point to the right ro om? Am I using one extra level of dictionary that I shouldn’t?
I tried multiple variant, but always getting ‘unknown’ as results…
Have you tried using “bedroom1”, etc. as json_attributes?
And in your template sensor the indentation of value_template is wrong, and the sensor’s entity id looks wrong - superfluous “csensor” and I assume that there is currently no sensor that has “bedroom1” in its entity id?
Sadly, I tried again and again this evening, with the dictionary key in json_attributes, with/without csensor (which is the name of the rest sensor we refer to, I think I need it from what I saw in other conf), etc
Alright, first, what you forgot to mention is that in your log you should get an error message saying something like: homeassistant.exceptions.InvalidStateError: Invalid state encountered for entity id: sensor.csensor. State max length is 255 characters.
The reason for this is that the rest sensor by default just tries to store the whole JSON response as its state which in your case is larger than the allowed 255 characters.
Normally in this type of scenario I pick a simple value from the JSON like for example a timestamp, or the most significant value. To fix your configuration up, I’d suggest you just set a static value for now.
Next, to access the state or attributes of a sensor you start with '{{ states. (missing s in your configuration).
And lastly, you have to add the individual keys to the value template.
I was also confused since the beginning about this value_template that I didn’t understood the need!
This 255 char limit + this stupid s (that I noticed after posting my message ) + this double dictionary were too many errors simultaneously…
I really thank you for your effort on my config!
Honestly, I was surprised that it was so hard to find nice documentation about something I thought was common, do you know how I can improve that? propose an additional exemple in the official documentation or something like that?
Hello,
May be my question is stupid, but I need some help. I have a temperature and humidity sensor , working as a webserver in my home network.
With rest call I can read temperature or humidity, but I don’t know how can I read both.
Currently, I’m using the following code into config.yaml and I have the temperature.
sensor: