Help needed for custom device scheduling

Hi everyone,

I have a custom made board that pilots my heaters and gets current values from my appartment’s electrical panel.
It answers simple http requests with a small json string sent back.

I have been able to integrate it in HA with rest resources and template sensors like this:

rest:
  - resource: http://192.168.1.101/json/currents
    scan_interval: 21
    sensor:
      - name: "courants domotix"
        json_attributes_path: "$"
        device_class: power
  - resource: http://192.168.1.101/json/counters
    scan_interval: 30
    sensor:
      - name: "counters domotix"
        json_attributes_path: "$"
        device_class: power
  - resource: "http://192.168.1.101/json/pilote/"
    scan_interval: 31
    sensor:
      - name: "ordres pilotes domotix"
        json_attributes_path: "$"
  - resource: "http://192.168.1.101/json/relais/"
    scan_interval: 33
    sensor:
      - name: "ordres relais domotix"
        json_attributes_path: "$"


template:
  - sensor:
      - name: "Conso 0"
        unique_id: 'conso_0'
        device_class: power
        state:  >
            {% set courants_domotix_list = states('sensor.courants_domotix')|from_json %}
            {{ courants_domotix_list[0] }}

etc…

It works mostly, but I have a scheduling problem which undermines the reliability of it: the board is not able to process several requests at a time, so whenever 2 resources are refreshed at the same time, it fails.
There are 4 requests I want to refresh, so inevitably some end up at the same time (I have put odd periods to reduce stats, but it does not really solve it)

I’m looking for a way to force requests to be sent one at a time.

I have found out that I could create triggers at separate times, but I don’t know how to refresh the rest resource based on a trigger. It doesn’t seem possible.

Is there another way I could access the http answers that I could trig with a trigger ? or any other way to force the refresh of the resource without conflicts ?

If anyone has ideas or pointers…

Thanks

Set the rest sensor scan intervals to really long times (years). Then use the homeassistant update entity service to schedule sequential updates using an automation. e.g.

triggers:
  - trigger: time_pattern
    seconds: "/10"
actions:
  - action: homeassistant.update_entity
    target:
      entity_id: sensor.courants_domotix
  - delay: 1
  - action: homeassistant.update_entity
    target:
      entity_id: sensor.counters_domotix
  - delay: 1
  - action: etc...

Note that you still may get one resource collision after a Home Assistant restart when the rest sensors are restored (updated). There is nothing you can do about this.

Thanks a lot, I’ll try that

Just checking, you can’t use this as the resource can you? http://192.168.1.101/json

If you can then it would solve all your issues. You just have to update the attribute paths for the sensors to include the rest of the path.

Also you don’t need seperate template sensors. You can do all that in the restful sensor value_template.

No, the root adress would just not be recognized as a request.
There isn’t one with all data sent back, I have to request 4 times

I’ve set in place the trigger.
I’ve had a little trouble with defining the automation in configuration.yaml directly (never worked but it’s probably due to me being a complete noob at automations.)

I finally re-created it with the automation interface (+tweaking yaml) and it works !

Thanks again

1 Like