Recommended way to define scan intervals for sensors?

Being new to HA (docker latest-v8) I wonder about the concept in HA to define appropriate scan intervals for different sensor types and number of sensors connected to a sensor netowrk. Example: Having a 1-wire sensor network with abount 50+ sensors it takes some time to poll all sensors. I am using owserver as service provided as docker container and use the HA 1-Wire Integration. From known smarthome systems like FHEM or iobroker I know that polling update rate or scan intervals can be specified e.g. by entity.

Having spent considerable amount of time searching for a solution in HA I have not found a solution yet.
onewire-update-interval-caching topic 343711
onewire-add-scan-interval-option topic 311586
post look open state and the suggested solutions found here

are not clear to me.

Having a controlled and suitable sensor update rate in alignment with the physics (temp changes depend on media) it is also beneficial to reduce data to be stored. For keeping important historical data I am using an influxdb2.x and do not want this to be polluted with redundant data.

Could someone pls. recommend best way and hands-on example to define scan/polling interval of 300 seconds for my 1-wire sensors.

Thanx in advance for your help.

P.S. had to stripe links because new users can only post 2 links in a post.

Disable polling on the integration in the UI. Then use homeassistant.update_entity at whatever frequency you want via an automation.

- alias: 300 Second Polling
  trigger:
  - platform: time_pattern
    minutes: "/5"
  action:
  - service: homeassistant.update_entity
    target:
      entity_id: ... insert entity id here ...

Thanx @petro. I have found the switch to diable polling for the entity.

  1. Is adding this code in configarion.yaml correct? - any specific position?
- alias: 300 Second Polling
  trigger:
  - platform: time_pattern
    minutes: "/5"
  action:
  - service: homeassistant.update_entity
    target:
      entity_id: sensor.28_a76e77911801_temperatur
      entity_id: sensor.28_a76e77911802_temperatur
      entity_id: sensor.28_a76e77911803_temperatur

two more questions:
2. could the template of the 1-wire entitiy be extended to add the value of the alias directly in the GUI?
3. is there a way to make the alias editable through GUI ?

I have no idea what you’re asking here. Can you elaborate?

where do I need to add the suggested code ? and is the example above having multiple entities correct?

it’s an automation. Yes, that works for multiple entities.

Though the entities should be a list:

  action:
  - service: homeassistant.update_entity
    target:
      entity_id: 
        - sensor.28_a76e77911801_temperatur
        - sensor.28_a76e77911802_temperatur
        - sensor.28_a76e77911803_temperatur
1 Like

yep, wasn’t paying attention

1 Like

thanx. it is getting much clearer now …

Step1 disable the 30s HA automatic scan update interval for 1-Wire.

Step 2 setup automation in GUI - here example with 2 min update


The example shows only one entity but there could be added more; nice approach.

There is also possibility to modify in automations.yaml. manually as I have the sensor ID lists already.

Using more and more multi sensors such as combinations of DS2438 + DS1820 or DS2450 (next release) connected to one 1-wie device the re-definition of the polling intervall becomes a challenging task.

Assume there are 30 1-wire devices with each 3 sensors connected then this list is becomming 90 entries. My list today has already some 50 entries … with upcoming DS2450 it will get much longer.

suggest to add in the GUI a parameter to modify the default scanning interval from 30 seconds to custom value. will look now how to make such request in the right way …

This is unlikely to happen. It was changed to make it slightly difficult on purpose to prevent people with less understanding from spamming external servers (there were complaints made to Home Assistant in the past).

@tom_l
It was changed to make it slightly difficult on purpose to prevent people with less understanding from spamming external servers…

you misunderstood. it is not to get faster but much slower… with reasonable and maintainable efforts. here is how I think parameter could be limited in config_flow.py suitable for 1-wire devices. there is no way to poll all my sensors in 30 seconds :wink: . And updating long lists is error prone and loosing auto discovery.

DATA_SCHEMA = vol.Schema(
    {
        vol.Required(CONF_HOST, default=DEFAULT_HOST): str,
        vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
        vol.Optional("scan_interval", default=DEFAULT_SCAN_INTERVAL): vol.All(
            int, vol.Range(min=30, max=3600)
        ),
    }
)

The complaint that generated the change was about ICMP pings. Too many users were pinging external servers too frequently. As @petro indicates, you still have control over the ping interval. Here is how I ping a server on my LAN every ten seconds:

# In 2023.12.1 the polling frequency default is 30 seconds.
# You can change this in an automation:

alias: Ping-TenSeconds
description: Ping entities every ten seconds
trigger:
  - platform: time_pattern
    seconds: /10
condition: []
action:
  - service: homeassistant.update_entity
    target:
      entity_id: binary_sensor.zeus_ping
    data: {}
mode: single

@stevemann yes, I know as mentioned above in the thread.

Key point is that the argument about much too fast scan intervals could easily be mitigated with proper parameter limitation as suggested … then there is no point in that argument any more - right ?

my list would get near 100 lines and growing, which is error prone while loosing auto-discovery.

a hiericical way to define scan intervals is a key feature to fine tune smarthome systems and to optimize and limit amount of data needed to record. in serial slow networks it will even not be possible to scan in suggested intervals.

This will likely never get implemented. Just make an automation using a template pointing out integration entities and filtering what you don’t want. It’s a simple automation.

alias: Onewire every 30 seconds
description: Update onewire entities every 30 seconds
trigger:
  - platform: time_pattern
    seconds: /30
condition: []
action:
  - service: homeassistant.update_entity
    target:
      entity_id: "{{ integration_entities('onewire') }}"
    data: {}
mode: single

many thanx @petro this is exactly what I was looking for.
After having read your post How to enumerate entities belonging to an integration? and the templating docs I am getting clearer. You are right that with YAML a much finer selection shall be possible.

For my use case the selection needs to be narrowed further down to the entities of the onewire sensor platform, while other onewire platforms like switches or binary_sensor shall not be affected.

Ideally I am thinking about a three step selection
1+2: all entities from a specific platform (here sensor) inside an integration entity (here onewire) but I could not find a platform_entity selector.

{{ integration_entities('onewire')| platform_entities('sensor')}}
since sensor is the platform name this can be achieved with the following entity selection

3: then filter further down if needed e.g. to select specific channels from DS2450 family 20.

channel A = CO2

  {{ integration_entities('onewire')|regex_findall(find='sensor\\.20_[0-9a-zA-Z]+_voltage_a', ignorecase=False) }}

channel B = Temperature

{{ integration_entities('onewire')|regex_findall(find='sensor\\.20_[0-9a-zA-Z]+_voltage_b', ignorecase=False) }}

channel C= Relative Humidity

    {{ integration_entities('onewire')|regex_findall(find='sensor\\.20_[0-9a-zA-Z]+_voltage_c', ignorecase=False) }} 

is this how it is supposed to work?
appreciate a hint for best practise and/or related documentation reference.

have not received other suggestions and thus mark this as solution now.

here are diagrams after some testing LGTM so far.

from left to right polling intervals CO2 1min, Temperature 2min, Relative Humidity 3min

@tom-ha
was this code only an idea by you ? Or is it really working ?

I am asking, because I am trying to set the SCAN_INTERVAL via GUI in my custom_intgegration. (sensor integration)

Currently I am adding the intervall in the const.py

SCAN_INTERVAL = timedelta(seconds=60)  # updateinterval in seconds

globally for all my entries.

So far this is working.

My question is, (if this code is rerally working) if I use the code in my config_flow.py data template how is Home Assistant handling / update this value ?

Because if I check my entities in developer tool, they dont have the attribute for scan_interval.