Throttling sensor updates to HA, but allow instant retrieval via API?

Hey,

so I’ve build a custom component on esphome that basically acts as a modbus proxy/“translator” from one device to two other devices (power meter → solar/car loading point).
It polls the power meter modbus every 1.5 seconds and then responds to other modbus devices, usually every ~2 seconds (when requesteed)
And it updates sensors every 15 seconds for the values to be available in HA (I don’t need that frequent data in HA, and since I’m using influxdb and a bit longer storage on mysql that default, I don’t want to flood that with data every 1.5s)

Now I have another piece of python code running on a raspberry in which I would like to access the data every 2s (not always, but for about 1 hour every other day or so). But not sure how to achieve that?

I could update the sensor refresh time to 2s, but then this would flood HA also, plus I only need this frequent data infrequently
I also thought about creating internal: true sensors with a hope that they might be available via REST Api /events endpoint through event source, but that does not seem to be the case

Is there some smart way to achieve what I’m looking for?

Maybe if you you add include_internal: true to your web server component?

You could set a higher update_interval on the internal sensor and expose them as templates with a slower update_interval like in this yaml here: PZEM-016-OLED-2-OUT-ESPHome/wemos_d1_pzem016_display.yaml at d93a4cb8d832c46ebbefea8ecce4e421a18920cb · Gio-dot/PZEM-016-OLED-2-OUT-ESPHome · GitHub

Other option I could think of is to set the update_interval set to 0 (disable) and call the component update via a little script on your esphome node. You could than use a template switch to toggle between “fast” and “slow” updates :rocket:

1 Like

yep, it seems I missed the obvious one … :slight_smile: Tested, seems to be ok. Thank you !