Now my problem is that the ESP is constantly calculating the distance and sending signals even though it is not necessary every 0.1s to Home Assistant.
What I would like is that the Ultrasonic Sensor is not updating (or has an extreme long interval > 60min) and I am able to change the interval numerically (ideally) or alternate between a long and short interval via Home Assistant.
I have problems putting the right syntax together based on my code snippets. I managed to create a template sensor in ESP Home that shows up in Home Assistant:
Ideally I could now set the interval numerically in Home Assistant or at least define two intervals that I can switch when the button is pressed in HA:
update_interval_fast: 0.1s
update_interval_slow: 60s # or longer / off if possible?
How would that look like? I think it should be somehow solvable with lambda but I am no expert in the syntax. I also looked into working with “delta” but it does not really achieve what I am looking for.
And link it to a binary sensor in the ESP Home yaml:
sensor:
- platform: ultrasonic
trigger_pin: 10
echo_pin: 1
name: "Ultrasonic Sensor"
id: ultrasonic_sensor
update_interval: 60s
binary_sensor:
- platform: homeassistant
id: high_speed_update
entity_id: input_boolean.high_speed_update
on_state:
- lambda: !lambda |-
// revert back to the default update interval
static uint32_t default_update_interval = id(ultrasonic_sensor).get_update_interval();
// 100 = 100 ms = New "high speed" interval
int update_interval = x ? 100 : default_update_interval;
id(ultrasonic_sensor).set_update_interval(update_interval);
id(ultrasonic_sensor).call_setup();
When the HA toggle is on the ultrasonic sensor updates every 100ms and when it is off only every 60s.
If there is an even more elegant way I would be happy about further suggestions. I try to work with this for now and see if there are any unintended consequences (maybe because of the call_setup()).
in the update_interval you can set the time you want for it to update but you can only set it on seconds or milliseconds. example 300s = 5 minutes. use google to calculate the seconds in minutes.
The setting vary from different platform and as i can see you are not using the ultrasonic platform. I have tried minutes in this platform and doesnt work.
oh, you have? lol. Why do you have to lie man? That’s complete BS and I know and you know it. Now since you can’t test something yourself and you’re going to sit here and lie then i’m gonna test it just for you sweet cheeks!
Here you go sweet pea! Next time don’t be lazy and do your own testing if you don’t want to embarrass yourself. All you had to do was put a sensor in a config and check it but, that was too difficult so you rather lie about it… shame shame
applaud your ridiculous attitude. Nobody asked you for opinion/test/check/fix anything. it works for you, amen. if it doesn’t work for me its none of your business, I didn’t asked you. Take your ridiculous attitude somewhere else crybaby.
I think you could alternatively do it without lambdas using the component resume action if you like.
That may avoid call setup (although I don’t know what’s happening under the hood).
You could also just have it at 0.1ms all the time and add a delta filter so you don’t spam HA when the value isn’t changing. But Maybe that is excessive and avoidable ongoing load on the sensor (not sure).
Adding a distance delta filter probably isn’t a bad idea either way (only send changes of more than say 1cm to HA, while internally you can use the raw data for your calcs).