Creating attributes (non JSON) on a rest sensor

I have been happily using restful sensors for a while now, and now that I am getting a lot more comfortable with the configuration files and started breaking them all down into packages I find I’m looking at the config and working on ways to make things better.

One of those is around my resfful sensors where I want to be able to specify attributes as well as the value_template based on the returned data. This would be very helpful especially in situations where the returned data exceeds the 255 character limit, but if I’m right, there doesn’t appear to be any way of defining attributes on a restful sensor other than json_attributes and they only point to specific properties from a JSON response.

I realise that you can create multiple sensors from the same rest API call, but attributes have their place as well and it seems odd there are no mechanisms to add them when you can on a template sensor.

Also, out of curiosity, why is state: not supported on restul sensors, I thought value_template was the old way of doing things and was being replaced.

I have no clue what your output looks like but instead of REST, I am using curl and pipe the output through JQ which allows me to define the output as wanted.

You might also consider the multiscrape integration which will give you the functionality to do templates in attributes.

As to your question about why REST doesn’t support this, or why it uses the old value_template option: I have no idea. Likely hasn’t been updated for a while.

1 Like

I changed my approach in the end, I stored the whole of the JSON body in an attribute and then I use a template sensor to parse the JSON. Found this works really well in situations where you are dealing with arrays of data

As with the original post…no clue as you provide no details, this post serves no-one sorry to say

The point of the post was to determine if the rest sensors could populate attributes, and that appears not to be supported.

I recognise there are other ways of doing it, as I stated I simply stored the whole JSON and processed that in another sensor to achieve my goal, I just couldn’t solve the problem with the restul sensor directly.

This forum is intended to ask/learn/share…none of that happened in this post, no details of the issue no details of the solution so why post?..this is my last comment and I hope you understand that pov