Howdy ESPHome Nerds. I have converted all of my Sonoff devices to ESPHome and I’m totally loving it. Question? When I power on a heater or battery charger I would really like to get 1 second power updates for a few minutes, then revert back to 60 seconds. Is it possible to send configuration changes “on the fly”? Thanks in advance for any guidance.
Hi David, welcome to the forum!
You cannot change the configuration of an ESPHome device on the fly and it’s not good practice.
You can solve this in HA.
Updates to what? Home Assistant or another esp32 device you can use as a monitor?
I did something like this in EspHome a while ago
This was to change the interval of a distance sensor when a certain door was detected as open in Home Assistant. Measuring the distance of a car from the wall, the car would only move when the door is open and then require frequent updates, otherwise only check once every 30 seconds
“distance” is the id of the sensor
worked for me about a year ago, but didn’t use it since.
binary_sensor:
- platform: homeassistant
name: "xxx open from homeassistant"
entity_id: binary_sensor.somedoor
id: opentrigger
on_state:
if:
condition:
# Same syntax for is_off
binary_sensor.is_on: opentrigger
then:
- logger.log: "Is open"
- lambda: !lambda |-
id(distance).set_update_interval(1*1000);
id(distance).call_setup();
else:
- logger.log: "Is Closed"
- lambda: !lambda |-
id(distance).set_update_interval(30*1000);
id(distance).call_setup();
Armin
Nick thanks for the input. Yes I know I can play with the data in HA but this means that I have to have the device output every second all the time which is no problem but generates a lot of unnecessary network traffic that doesn’t get used 99.99% of the time LOL. I’m also guessing there may be a way to program this in the configuration - to transmit based on rate of change of power. I was hoping somebody has done this already
So for example. When I turn on my RV battery charger, is starts out at 250 watts, but the power value power reading in HA shows the average of the last 60 seconds which usually comes out to 30ish watts - waaay off, then a minute later shows the correct 250 watts. I’d like to stop 60 second averaging on the device for a few minutes - then ramp up from 1 second averages up to 60 after a few minutes. It’s just that leaving it at 1 second averaging on the device all the time and doing the taper in HA is DISTURBING because the “network chatter” from the device is 60 times higher (1 second update compared to 60) LOL
try this with your switch
on_turn_on:
then:
- lambda: |-
id(my_sensor)->set_update_interval(1000);
- delay: 1min
- lambda: |-
id(my_sensor)->set_update_interval(60000);
not tested…
I found some code that should have worked. They have you disable the power sensor publish with update_interval: never,
then you create a template sensor where you use any lambda code to “play with” your desired interval, and then return the value of the power sensor as the sensor data
Unfortunatly, the Sonoff S31’s power sensor, the CSE7766, does not recognize the update_interval command. It broke in 2024. You can only control the interval of this sensor using a filter.
/config/s31-b581.yaml:58:17: error: ‘class esphome::sensor::Sensor’ has no member named ‘set_update_interval’
I guess I could just leave update_interval alone and run the code anyway !!!. Well no I can’t do that because I need throttle_average: 1s which would mean that it publishes power every second even though my template sensor would eventually drop to 60s.
Maybe I can just manipulate throttle_average? … HMMM
I punted and set my throttle_average: 1s and delta: 10. This basically does what I wanted: update fast when the power is changing rapidly but slow down as it stabilizes.
Guess I’ll have find a power sensor other than the CSE and build my own ![]()
Your way looks Tre-Kewl. Sadly, I expect it won’t work (nor Armin’s code) because update_interval doesn’t
Dang … I thought the S31 was God’s gift to smart plugs ![]()
Thanks … Grabber