Read JSON file into sensor

I have a json file on my computer - in the config folder along with my config yaml etc…
I was thinking I could use a restful sensor to read that in but that only seems to read from a URL.

Is there any way to read from a file instead of a url?

You could create a python script to read it and then send it to a mqtt topic

I could do the whole thing in python but I don’t know python.
I am currently using a bash script to get the data and publish to mqtt but this could be a problem for a hassio user who can’t access mosquitto_pub

You could use your bash script to call curl and POST the sensor state directly to HA using a long-lived access token.

1 Like

Ah… that is worth investigating! Thanks for that tip. Didn’t even think of that.

Well!!! That WORKED… Who would have thought! Thanks so much!

1 Like

Hi David !

Can you share your solution ? I’m also interested in reading json file data and use it as sensor
Thanks!

Have a look at my scripts here https://github.com/DavidFW1960/ABB-Home-Assistant-Usage

2 Likes

I have the same situation where the following datafile needs to be read into a sensor in order to be used in the ApexxCharts Card. If you have been successful to accomplish this could you give me a lead how to go about. I’m totally alien to python.

[[1615404900000,0.7],[1615405200000,0.3],[1615405500000,1],[1615405800000,2.1],[1615406100000,1.7],[1615406400000,0],[1615406700000,0],[1615407000000,0.7],[1615407300000,1],[1615407600000,0.7],[1615407900000,0.3],[1615408200000,0.3],[1615408500000,0.8],[1615408800000,2.1],[1615409100000,0.8],[1615409400000,0.1],[1615409700000,0],[1615410000000,0.1],[1615410300000,1.2],[1615410600000,2.1],[1615410900000,5.2],[1615411200000,4.9],[1615411500000,1.5],[1615411800000,0.7]] 

Appreciate your guidance!

Have you been able to work this out and if so willing to provide some guidance?