Sorry, I was blind . Have you tried it with the content type header? Same result?
I don’t know how I can add that to my Node Red raw json datafile, it would have to be an html file, wouldn’t it? As I said it works from my web server, just uploading the basic raw datafile
That is for your REST sensor in HA:
- platform: rest
name: planes
resource: http://192.168.1.130/share/airdata.json
value_template: >
{{ value_json.airplanes | length }}
method: GET
headers:
Content-Type: application/json
scan_interval: 60
json_attributes:
- "airplanes"
- "flight"
- "height"
- "speed"
- "dir"
- "lat"
- "lon"
- "alt"
- "km"
- "nm"
- "azimuth"
- "elev_angle"
- "state"
- "ts"
- "last_updated"
No that doesn’t make any difference, there is no sensor loaded
I have also tried this, but doesn’t work.
It just has to be possible to get HA to use a local json file, but I cannot find any proper info to help
- platform: file
name: planes
file_path: /share/airdata.json
value_template: >
{{ value_json.airplanes | length }}
method: GET
headers:
Content-Type: application/json
scan_interval: 60
json_attributes:
- "airplanes"
- "flight"
- "height"
- "speed"
- "dir"
- "lat"
- "lon"
- "alt"
- "km"
- "nm"
- "azimuth"
- "elev_angle"
- "state"
- "ts"
- "last_updated"
You changed from REST to file and your parameters don’t look correct. Take a look at this thread, it might help you get to the result you are after:
After much reading I now understand that you cannot load a local json file as an html webpage which, fails due to Access-Control-Allow-Origin viotaion.
You can if you put it your home assistant folder set and use ip:8123/path_to.json
Thank you for that information, I have been tearing my hair out for days.
I have the file in the /share/ folder, do you mean the /config/ folder and if so, which subfolder should use?
You can choose whatever you like within the www folder.
I have many such files.
For example, physically located in “www” I create a folder for the subject, for example “Roborock”.
.homeassistant/www/Roborock
Inside that folder I place a file say “roborock.json”
Then I use (inside an included sensor.yaml) using “local” to refer to the “www” path:
##
## Roborock Rooms
##
- platform: rest
name: roborock_rooms
resource: http://192.168.1.245:8123/local/Roborock/roborock.json
value_template: "{{ now() }}"
json_attributes:
- rooms
- points
Note that 192.168.1.245:8123 is my homeassistant instance. Be sure to set appropriate access rights for homeassistant user to access the file.
Now, I would think that in the first instance you show above, you control the web site. So you can set it up to add Access-Control-Allow-Origin for the homeassistant instance or even “*” for anything. But I prefer to have all mine in the instance themselves for backup and portability.
In another instance I have I actually create a main folder called “custom” and then place everything in folders under that one. It is a bit cleaner that way as then it exists at the same level as “community”, “icons”, “images” …
Thank you so much, I am going to try this later on as I have to go out
I will post the results.
Cheers
You genius,
You might just have saved the last hair on my balding head.
I knew it must be possible, thank you so much for your help, you have no idea how many hours I have spent on this trying all sorts of ingenious web server ideas to get this done. I can’t give up when I get this near to solving a puzzle, and having just turned 72 years old, this keeps my brain churning around.
I am off to have a beer to celebrate
You are welcome … I am 62 so its us oldies sticking together!
Ha ha oldies but goldies, I have lots of other ways I can use this, I am on a roll now and there is no stopping me. Have a nice evening
Excellent. A few of mine are:
- I use the Roborock one to maintain the list of zones to nice names
- I have 5 Vizio TVs with DirecTV and have large JSON file for each TV+DIrecTV pair to create super remotes that add things like “favorite channels”
- I have a CSV with the top 1200 music artists that populates a dropdown to select an artist and play on Pandora or Spotify
- My IBBQ integration where I maintain a map of temperatures, doneness and meat type for easily selecting the set temperatures for the probes
Hi kbrown01,
Everything has been working just great until about 4pm this afternoon when suddenly I have an error message as follows
“failed to write to file: Error: ENOENT: no such file /config/www/community/skyware/airdata.json”
I know that that the SAMBA has been updated but I can’t see if I should change the path and it didn’t coincide with the update.
Any ideas?
Is that file there? And it seems confusing … it says failed to write to file … are you editing the file with some code as creating a sensor is not writing anything.
Since an update to the Samba and latest HA, there is an issue with the way you address save and read your json files.
With a little help and a lot of experimentation I have discovered the correct way of addressing files generated in Nodered and reading them in HA.
Here are the details in brief
Here is the proceedure:-
1 The mapping in config is a must
map:
- addon_config:rw
- homeassistant_config:rw
- media:rw
- share:rw
- www:rw
- local:rw
- ssl
2 Nodered write file has to be /homeassistant/www/community/myfolder/myfile.x
3 The REST resource url has to be http://192.168.1.130:8123/local/community/myfolder/myfile.x
Ah, so it really is a Node Red thing. I don’t use that and mine all function fine. I have oXygen editor directly linked via Samba to .homeassistant directory and browse/edit by hand those files.
OK, well I use Nodered because it is the easiest way for me to do some add on processing to other files. The one big issue with nodered is that it seems virtually impossible to write a file that can be processed on any other machine on the network, never mind to HA on the same machine.