Update_interval & internal option problem

Hello.
I use adc sensor to get values and binary threshold to detect limit.

I would like to not expose adc value to HA. Then I use “internal: true” perfect. It work.

BUT like this, adc is readed every 60 sec. I need faster read (1s) otherwise I miss events of course.

Then I add “update_interval: 1s”. It work, perfect.

But it overwrite the internal:true setting. Analog value is sent every second… I just need threshold filtered value.

It make lot of traffic, cause I have 6 sensor every second. … I just need threshold value when it changes.

How can I force frequent internal adc reading without exposing/posting to HA ?

Thanks a lot !

It really doesn’t make a lot of traffic. The native api is very efficient and shouldn’t even send values if they didn’t changed. I have around 100 esphome nodes and some have a 0.1 second interval (like power meters for example). No problems what so ever (beside on the ha side the database grows big fast!) with the amount of traffic - it’s peanuts :peanuts: in the end. Every phone that streams a video probably transmits more traffic in a second than an average esphome node transmits in a whole day.

So beside this “lot of traffic” doesn’t seem to look plausible in any matter you can still “throttle” the amount of data you send to ha while keeping a high internal update interval. :chart_with_upwards_trend:

As a example check this yaml :point_down:

I think this is what your asking for but not 100% sure.

Goes under your sensor. So you have “update_interval: 1s” then 1 x 60 = 60 seconds. HA will get a average every 60 seconds. If you would like to receive a actual number close to average then make the number odd like 61

    filters:
    - median:
        window_size: 60
        send_every: 60
        send_first_at: 6

if this is not what you are looking for have a read of filters.

i’m sorry if you understand the traffic is a problem. I just want to understand the way it work to find the finest way to do it.
maybe it was better if i just asked “can i keep ADC internal even for fast ADC read (1sec)”.
i read ADC voltage from alarm system (sensor/area). i put an treshold to detect if sensor detect or not human.
Then i need fast read (60 sec has no sense). but i dont need to transmit voltage to HA. only changes between DETECT and NOT DETECT (the threshold sensor linked to ADC read)

thank you for your example. but it don’t seems to help me to resolve my problem/question.

You can then just keep the adc sensor internal with the refresh interval you want and create a analog threshold binary sensor which is exposed to ha. :star2:

Then maybe sensor automation “on_value_range”

Really no need for this. Internal adc sensor and a analog threshold binary sensor which is exposed to ha is everything the author needs :bulb:

You can then just keep the adc sensor internal with the refresh interval you want and create a analog threshold binary sensor which is exposed to ha. :star2:

It’s exactly my problem my dear ! look at this :

This one expose “Z1” & “Z1 detect hall” to HA !!! (seems that update_interval force internal to false ) but it work, every second an ADC measure and threshold updated.

sensor:
  - platform: adc
    pin: GPIO36
    name: "Z1"
    id: "Z1"
    update_interval: 1s
    attenuation: 11db
    internal: true
- platform: analog_threshold
    name: "Z1 Detect Hall"
    sensor_id: "Z1"
    threshold: 1.8

And next one (without update_interval) expose only Z1 detect hall (good, internal stay true) , but adc take 1 measure every 60 sec then threshold is also updated every 60 sec too. too slow to get alarm infos. need 1 or max 2 seconds !

sensor:
  - platform: adc
    pin: GPIO36
    name: "Z1"
    id: "Z1"
    attenuation: 11db
    internal: true
- platform: analog_threshold
    name: "Z1 Detect Hall"
    sensor_id: "Z1"
    threshold: 1.8

My apologies if it was not clearly explained before !

Indeed, as start you might wanna read this post here which explains how to ask a good question:

but for now back to you problem:

That shouldn’t happen. As a test you can try to remove name: "Z1" and only keep the id: "Z1" to see if it makes a difference.

the indentation/spacing is wrong in your yaml snippet btw.

Thanks for your answer ! i try to do my best. sorry.
The indetnation was a copy/paste problem, see this screenshot, adapted with your advice “remove name Z1” (i removed, Z2…Z6 to allow you to see indentation) :

Screenshot from 2022-09-20 21-54-52

and here is the result, continue to post/expose Z1 every second :

what can i do ? what’s your advice ?

kind regard.

I have an ADC input that reads every 0.125s, but I only publish per minute… (mic2_adc does not show up in HA)

You just gotta do the math between update_interval and the windows_size/send_every

  - platform: ads1115
    multiplexer: 'A1_GND'
    gain: 4.096 #(measures up to 4.096V)
    name: "mic2_adc"
    id: mic2_adc
    update_interval: 0.125s
    internal: true
    unit_of_measurement: "dB"
  - platform: template
    name: mic2_db_60s_peak
    id: peak2_decibels
    unit_of_measurement: "dB"
    update_interval: 0.125s
    lambda: return id(mic2_adc).state;
    filters:
      - max:
          window_size: 480
          send_every: 480
          send_first_at: 23 

thx, but can you try to add an “analog_threshold” to see if perturb “internal: true” ?

No. This template approach works, you test it.

The analog threshold hard-codes the value in the compile, I don’t like that. It means every time you want to try a new setting, you have to recompile. I use a helper in HA to hold my threshold so I don’t have to recompile and it allows me to change it easily as needed, on the fly.

OK, then problem still there :

How to send 'immediately" (1sec) only “status under/over” changes status when ADC voltage is over/under 1.8V. then without voltage every second.

As sometimes it seems a make bad explainations i say it other way :
ADC changes over/under threshold must be detected/sent in the second. But without post voltage every second.

Any advice ? Thanks a lot.