I have a battery powered device that wakes up for a short time when running on battery but stays awake when externally powered. I also have a battery voltage sensor in that device that by default sends it value once every other minute. Right now I use sliding_window_moving_average filter to send one value out after boot and then every two minutes but sometimes connecting to the api takes a bit longer so the first value doesnt make it and the device is sleeping again before the next value gets sent.
So my question: Is there a way to wait with sending the first value until the api is connected and after that every 2 minutes? I did not find anything about that in the documentation.
I see, but how would I trigger sending the value from the battery sensor then? The docs only describe sending a value to the sensor, but not how to trigger the sensor to take and send a measurement now…
sensor:
# battery voltage measurement for guesstimating battery state
- platform: adc
name: "Battery voltage"
id: battery_voltage
pin: GPIO34
accuracy_decimals: 2
update_interval: 5s
entity_category: DIAGNOSTIC
device_class: VOLTAGE
state_class: measurement
internal: False
attenuation: auto
filters:
- sliding_window_moving_average:
window_size: 24
send_every: 24
send_first_at: 1
- multiply: 2.0 # multiply by 2 because of voltage divider
This sends the first value after 5 seconds and then one every 2 minutes but sometimes the first one doesnt get through because the api isnt connected yet.
When using the interval I would probably do something like this:
But the last line is what is missing for me right now… of course I would need to add another condition to make sure this only happens once because i do not want it sent every second but that I can do
Though I am not sure if global_api_server->is_connected() is the best way but that’s what google found to get the api connected state in a lambda… also missing in the documentation as far as I can see