Rest API help needed (Multiple data from one resource)

Just see this - Its slamming my poor box every ms.
Scan interval is set at 10s

2022-08-29 13:03:02.762 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {
	"Code":	0,
	"Result":	{
		"UpdateInterval":	{
			"EnMap":	0,
			"Value":	10
		},
		"DataValidTime":	{
			"EnMap":	0,
			"Value":	6
		},
		"Point":	[{
				"Name":	"CAP_B",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	42,
				"Writable":	0,
				"EnMap":	0
			}, {
				"Name":	"cap_av_b",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	42,
				"Writable":	0,
				"EnMap":	0
			}, {
				"Name":	"DP_B",
				"Unit":	"KPa",
				"Type":	"float",
				"Value":	1778.719360,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SP_B",
				"Unit":	"KPa",
				"Type":	"float",
				"Value":	534.897644,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SCT_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	48.569424,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SST_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	7.935587,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"DEFRT_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	-17.777779,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"speed_b",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	0,
				"Writable":	0,
				"EnMap":	0
			}],
		"RegStart":	0
	}
}
2022-08-29 13:03:02.762 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.sp_b, old_state=None, new_state=<state sensor.sp_b=unknown; friendly_name=SP_B @ 2022-08-29T13:03:02.762750+04:00>>
2022-08-29 13:03:02.763 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {
	"Code":	0,
	"Result":	{
		"UpdateInterval":	{
			"EnMap":	0,
			"Value":	10
		},
		"DataValidTime":	{
			"EnMap":	0,
			"Value":	6
		},
		"Point":	[{
				"Name":	"CAP_B",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	42,
				"Writable":	0,
				"EnMap":	0
			}, {
				"Name":	"cap_av_b",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	42,
				"Writable":	0,
				"EnMap":	0
			}, {
				"Name":	"DP_B",
				"Unit":	"KPa",
				"Type":	"float",
				"Value":	1778.719360,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SP_B",
				"Unit":	"KPa",
				"Type":	"float",
				"Value":	534.897644,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SCT_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	48.569424,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SST_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	7.935587,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"DEFRT_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	-17.777779,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"speed_b",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	0,
				"Writable":	0,
				"EnMap":	0
			}],
		"RegStart":	0
	}
}
2022-08-29 13:03:02.763 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.sct_b, old_state=None, new_state=<state sensor.sct_b=unknown; friendly_name=SCT_B @ 2022-08-29T13:03:02.763810+04:00>>
2022-08-29 13:03:02.764 DEBUG (MainThread) [homeassistant.components.rest.sensor] Data fetched from resource: {
	"Code":	0,
	"Result":	{
		"UpdateInterval":	{
			"EnMap":	0,
			"Value":	10
		},
		"DataValidTime":	{
			"EnMap":	0,
			"Value":	6
		},
		"Point":	[{
				"Name":	"CAP_B",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	42,
				"Writable":	0,
				"EnMap":	0
			}, {
				"Name":	"cap_av_b",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	42,
				"Writable":	0,
				"EnMap":	0
			}, {
				"Name":	"DP_B",
				"Unit":	"KPa",
				"Type":	"float",
				"Value":	1778.719360,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SP_B",
				"Unit":	"KPa",
				"Type":	"float",
				"Value":	534.897644,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SCT_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	48.569424,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"SST_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	7.935587,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"DEFRT_B",
				"Unit":	"°C",
				"Type":	"float",
				"Value":	-17.777779,
				"Writable":	0,
				"EnMap":	0,
				"EnMapAdd":	0
			}, {
				"Name":	"speed_b",
				"Unit":	"%",
				"Type":	"unsigned",
				"Value":	0,
				"Writable":	0,
				"EnMap":	0
			}],
		"RegStart":	0
	}
}
2022-08-29 13:03:02.764 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.sst_b, old_state=None, new_state=<state sensor.sst_b=unknown; friendly_name=SST_B @ 2022-08-29T13:03:02.764842+04:00>>
2022-08-29 13:03:02.765 

So, the behaviour is the same as modbus(I now have removed the modbus option as the library was old and is not maintatined well - was giving so many errros)

My problem is the same that means - HA doesnot respect scan interval - It will create a request for EACH sensor.

Any other solution other than Node red(native in HA) - Node red is additional maint point for me.

Adding - Exact behaviour of modbus. HA fails here disgracefully again (I thiugh it was modbus which was creating issue) - The senors value become unavavailable, expected, but later becomes random - It looses tracks of sensors. One sensor value becomes other sensor value.

There is something seriously wrong here.

Typically people will create a single rest sensor with the “OK” value - and all the JSON returned as an attribute, and then use template sensors to get the data out of the attributes of the main sensor.

So you would for example do something like set the attributes for the main sensor like this:

json_attributes:
  - "Result"

And then all the JSON under the Result key would be available as an attribute in the main sensor, which you could then access with template sensors:

{{ state_attr('sensor.my_rest_sensor','Result')['Point'][0]['Value'] }}

Makes sense. Let me try that.

Just updated the post, because it should be json_attributes instead of attributes

https://community.home-assistant.io/t/restful-sensor-state-attr-unknow-and-json-attributes-path-solved/373285/2
Please see this topic-21 Dec - tom_l, who is moderator(and assuming participating in maintaining) is writing clearly that one call is made and multiple sensors are updated using that call.

That is incorrect - As I see using my code is slamming my json box.

As I wrote above, my jason syntaxing is poor. I just cannot make head or tail from making single call and filling the sensor using your method. I tried and got stuck.

    scan_interval: 5
    resource: http://192.168.39.14/app/config/0/0
    sensor:
      - name: "HVAC_0"
	    value_template: "OK"
	    json_attributes:
          - "Result"
            {{ state_attr('sensor.HVAC_0')['Point'][0]['Value'] }}

Remove the last line (the template)

That goes in the template sensor.

template:
  - sensor:
      - name: "ctr_type"
        state: "{{ state_attr('sensor.HVAC_0','Result')['Point'][0]['Value'] }}"
      - name: "runstate"
        state: "{{ state_attr('sensor.HVAC_0','Result')['Point'][1]['Value'] }}"

etc

… If you need to have them in separate sensors.
Most of the times I prefer to have one sensor with all values as attributes to make it easier to see all values at one time.
You can still use the attributes in automations or whatever you need the values for.

1 Like
template:
  - sensor:
      - name: "hvac_0_combined"
        state: "{{ state_attr('sensor.HVAC_0','Result')['Point'][1]['Value'] }}"
        attributes:
          ctr_type: "{{ state_attr('sensor.HVAC_0','Result')['Point'][0]['Value'] }}"
          runstate: "{{ state_attr('sensor.HVAC_0','Result')['Point'][1]['Value'] }}"
          chil_s_s: "{{ state_attr('sensor.HVAC_0','Result')['Point'][2]['Value'] }}"

etc - to create a single sensor as @Hellis81 has suggested.

Will something like this work (As I said - I dont know the basics of json)- Trial and error

    scan_interval: 5
    resource: http://192.168.39.14/app/config/0/0
    sensor:
      - name: "HVAC_0"
	    value_template: "OK"
	    json_attributes:
          - "Result"
    resource: http://192.168.39.14/app/config/0/1
    sensor:
      - name: "HVAC_1"
	    value_template: "OK"
	    json_attributes:
          - "Result"
template:
  - sensor:
      - name: "ctr_type"
        state: "{{ state_attr('sensor.HVAC_0','Result')['Point'][0]['Value'] }}"
      - name: "runstate"
        state: "{{ state_attr('sensor.HVAC_0','Result')['Point'][1]['Value'] }}"

and son on (notice that I am pulling each page as HVAC_0 and HVAC_1 etc

Something is missing.
Is this supposed to be a RESTful Sensor - Home Assistant (home-assistant.io) or RESTful - Home Assistant (home-assistant.io) ?

What you posted will not work. But we need to know which route you are trying to use now.

Yes that looks fine.
One quick note - ALL sensor names are lowercase in Home Assistant - so it would be:

state_attr('sensor.hvac_0','Result')['Point'][0]['Value']

I should have noticed in my previous examples.

No it doesn’t.
There are duplicate resource and sensor.
There should be - somewhere but it depends on the route he is trying now.

I assumed it was just a copy and paste issue - because he had the correct format in the first post. (Resource had a -)

rest:
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 2
    resource: http://192.168.39.14/app/config/0/0
    sensor:
      - name: "HVAC_0"
	    value: "OK"
        json_attributes:
          - "Result"
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 2
    resource: http://192.168.39.14/app/config/0/1
    sensor:
      - name: "HVAC_1"
	    value: "OK"
        json_attributes:
          - "Result"

(Personally I wouldn’t drop the scan interval any lower than 10 seconds though… ask yourself if you really need updates every 2 seconds? Aside from the huge amount of data that will add to the database - it’s going to be making Home Assistant pretty busy)

1 Like

Yes - Its retsful sensor.
There is only a small page in HA help pages and that too is incomplete. It doesnot show the original jason , and just gives the example without reference. Thats why the confusion.

If you read my jason results above - You will get what I want.

Andrew Jones walked me through it but I was misled by post from Dec21 that it was a single jason request,

This is wrong. The resource is called once for each configuration in the rest integration and the data is passed to each sensor listed in the sensor section. This comment lead to @nitinuae opening old threads to spread more miss-information.

He could have 1 rest call with all his sensors with the following configuration. Notice the rest resource is different (removed last index) and the addition of json_attributes_path.

rest:
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 2
    resource: http://192.168.39.14/app/config/0
    sensor:
      - name: "HVAC_0"
	    value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
      - name: "HVAC_1"
	    value: "OK"
        json_attributes_path: $.1
        json_attributes:
          - "Result"

To further clarify, the rest integration is 1 resource call → update multiple sensors. The rest sensor platform is 1 resource call → update 1 sensor.

Oops - I did open old thread - and In fact I hit another rate limitation helper thread (I hit rate limitation INSIDE of HA).

I will now try what you have written above and report.

Its not allowing me to restart.
Invalid config for [rest]: [value] is an invalid option for [rest]. Check: rest->rest->0->sensor->0->value. (See ?, line ?).

CHECK CONFIGURATIONRESTART
Here is my full file -

rest:
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 7
    resource: http://192.168.39.14/app/config/0/0
    sensor:
      - name: "hvac_0"
        value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
          
          
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 8
    resource: http://192.168.39.14/app/config/0/1
    sensor:
      - name: "hvac_1"
        value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
          
          
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 9
    resource: http://192.168.39.14/app/config/0/2
    sensor:
      - name: "hvac_2"
        value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
          
          
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 10
    resource: http://192.168.39.14/app/config/0/3
    sensor:
      - name: "hvac_3"
        value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
          
          
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 11
    resource: http://192.168.39.14/app/config/0/4
    sensor:
      - name: "hvac_4"
        value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
          
          
  - authentication: basic
    username: "xx"
    password: "xx"
    scan_interval: 6
    resource: http://192.168.39.14/app/config/0/5
    sensor:
      - name: "hvac_5"
        value: "OK"
        json_attributes_path: $.0
        json_attributes:
          - "Result"
          
          
template:
  - sensor:
      - name: "ctr_type"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][0]['Value'] }}"
      - name: "runstate"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][1]['Value'] }}"
      - name: "CHIL_S_S"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][2]['Value'] }}"
      - name: "CHIL_OCC"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][3]['Value'] }}"
      - name: "min_left"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][4]['Value'] }}"
      - name: "ALM"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][7]['Value'] }}"
      - name: "CAP_T"
        unit_of_measurement: "%"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][13]['Value'] }}"
      - name: "SP"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][17]['Value'] }}"
      - name: "CTRL_PNT"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][18]['Value'] }}"
      - name: "CTRL_WT"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][19]['Value'] }}"
      - name: "OAT"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_0','Result')['Point'][20]['Value'] }}"
      - name: "CAP_A"
        unit_of_measurement: "%"
        state: "{{ state_attr('sensor.hvac_1','Result')['Point'][0]['Value'] }}"
      - name: "DP_A"
        unit_of_measurement: "kPa"
        state: "{{ state_attr('sensor.hvac_1','Result')['Point'][2]['Value'] }}"
      - name: "SP_A"
        unit_of_measurement: "kPa"
        state: "{{ state_attr('sensor.hvac_1','Result')['Point'][3]['Value'] }}"
      - name: "SCT_A"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_1','Result')['Point'][4]['Value'] }}"
      - name: "SST_A"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_1','Result')['Point'][5]['Value'] }}"
      - name: "CP_A1"
        state: "{{ state_attr('sensor.hvac_2','Result')['Point'][0]['Value'] }}"
      - name: "CP_A2"
        state: "{{ state_attr('sensor.hvac_2','Result')['Point'][1]['Value'] }}"
      - name: "FAN_A1"
        state: "{{ state_attr('sensor.hvac_2','Result')['Point'][3]['Value'] }}"
      - name: "CAP_B"
        unit_of_measurement: "%"
        state: "{{ state_attr('sensor.hvac_3','Result')['Point'][0]['Value'] }}"
      - name: "DP_B"
        unit_of_measurement: "kPa"
        state: "{{ state_attr('sensor.hvac_3','Result')['Point'][2]['Value'] }}"
      - name: "SP_B"
        unit_of_measurement: "kPa"
        state: "{{ state_attr('sensor.hvac_3','Result')['Point'][3]['Value'] }}"
      - name: "SCT_B"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_3','Result')['Point'][4]['Value'] }}"
      - name: "SST_B"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_3','Result')['Point'][5]['Value'] }}"
      - name: "CP_B1"
        state: "{{ state_attr('sensor.hvac_4','Result')['Point'][0]['Value'] }}"
      - name: "CP_B2"
        state: "{{ state_attr('sensor.hvac_4','Result')['Point'][1]['Value'] }}"
      - name: "FAN_B1"
        state: "{{ state_attr('sensor.hvac_4','Result')['Point'][3]['Value'] }}"
      - name: "EWT"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_5','Result')['Point'][0]['Value'] }}"
      - name: "LWT"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_5','Result')['Point'][1]['Value'] }}"
      - name: "reset"
        unit_of_measurement: "°C"
        state: "{{ state_attr('sensor.hvac_5','Result')['Point'][13]['Value'] }}"
      - name: "PUMP_1"
        state: "{{ state_attr('sensor.hvac_5','Result')['Point'][18]['Value'] }}"
      - name: "PUMP_2"
        state: "{{ state_attr('sensor.hvac_5','Result')['Point'][19]['Value'] }}"


est:
 - authentication: basic
   username: "xx"
   password: "xx"
   scan_interval: 2
   resource: http://192.168.39.14/app/config/0
   sensor:
     - name: "HVAC_0"
       value: "OK"
       json_attributes_path: $.0
       json_attributes:
         - "Result"

Should I make value: “OK”
to
Value_template: “OK” ?