raw json data 

JSON Structure for a List of Objects:

[
  {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3"
  },
  {
    "key1": "valueA",
    "key2": "valueB",
    "key3": "valueC"
  },
  {
    "key1": "valueX",
    "key2": "valueY",
    "key3": "valueZ"
  }
]

 

Create the Entity

/data/homeassistant202405/configuration.yaml

#
# ----------------------------------- rest -----------------------------------
#
rest:
  - resource: https://github.com/NateScarlet/holiday-cn/blob/master/2025.json
    scan_interval: 86400   # Refresh once per day
    sensor:
      - name: "ChinaHoliday"
        value_template: "{{ value_json.days | length }}"
        json_attributes_path: "$"
        json_attributes:
          - days

 

Usage in Home Assistant Automations:

 

 

 

20261128

step 1.physically located in “www” I create a folder for the subject, named with “holiday-cn”.

data/homeassistant/www/holiday-cn

step 2. download 2027.json from github 

Inside that folder I place a file say “2027.json”

data/homeassistant/www/holiday-cn/2027.json

step 3.

using “local” to refer to the “www” path

#
# ----------------------------------- rest -----------------------------------
#

#  http://localhost:4999/boards/topic/54381/rest#82190
rest:
  - resource: http://192.168.2.125:8123/local/holiday-cn/2027.json # https://github.com/NateScarlet/holiday-cn/blob/master/2027.json
    scan_interval: 86400   # Refresh once per day
    sensor:
      - name: "ChinaHoliday"
        value_template: "{{ value_json.days | length }}"
        json_attributes_path: "$"
        json_attributes:
          - days

 

useful links

https://community.home-assistant.io/t/how-do-i-get-a-local-json-file-to-load-using-rest-or-file/635033/13

Comments


Comments are closed