Hey everyone, I set up an esp32 nutrient dosing system for myself using peristaltic pumps, and it works reliably for me. However I just set one up for a friend of mine, and the script doesn’t always shut down the pump when it should. It seems like it’s a communication error between the esp32 and HA laptop, but i’m not sure. ESP32 logs show strong signal, with no errors (that I can see). Here is the script in question
Best,
Gabe
alias: Cal Mag Dispense
sequence:
- type: turn_on
device_id: f8d392972003648734f1bec5f75da9d3
entity_id: switch.calmag_pump
domain: switch
- delay:
hours: 0
minutes: 0
seconds: 0
milliseconds: "{{ states('input_number.cal_mag') | multiply(380) | int }}"
- type: turn_off
device_id: f8d392972003648734f1bec5f75da9d3
entity_id: switch.calmag_pump
domain: switch
mode: single
icon: mdi:water-pump
Don’t put time-sensitive automations on the Home Assistant server. Rather, run them on ESPHome itself. This way, they’ll be timed perfectly, and, as a bonus, won’t even need an active connection.
Before you ask: Yes, you can read Home Assistant values using ESPHome
that sounds lovely, any idea how id adapt the code to esphome? My only experience with esphome is setting up switches, not so much automation
No worries!
I, personally, would delete your helper input_number.cal_mag
and put it inside ESPHome itself. It will expose it, with the difference that it will be “managed” by ESPHome, and it can store it in between reboots. There’s an added benefit that if it boots without connection to HA, it will still remember the last value and execute the automation just fine.
Number Component — ESPHome
However, if you use the helper input_number.cal_mag
for multiple different ESP devices, it’s better to read it from HA itself (HA being a single truth source), using following method:
Platform “Home Assistant”
(Pick one!)
Then, just automate it like (above link already gave you a hint, but here’s the docs):
Automations and Templates — ESPHome
If you need further help, let me know!
You’re the man, thank you. I’ll get started on it
1 Like
I have the number and script sorted out (I believe), but I cant seem to figure out the best way to actually trigger the script with an input boolean
number:
- platform: template
name: "test ml"
id: test_ml
update_interval: 1s
optimistic: True
mode: box
initial_value: 0
min_value: 0
max_value: 100
step: 1
script:
- id: base_a_script
then:
- switch.turn_on: base_a
- delay: !lambda 'return id(test_ml).state * 1000;'
- switch.turn_off: base_a
You usually trigger the automation on some state, like “on_press” of a swich, a change in value or time.
Also, note that you can’t use all the variables like “optimistic” or “update_interval”, since ESPHome has it’s own names. Check the documentation once in a while!
Is “switch.calmag_pump” defined on the ESP? Or is that an external device?
If it’s on the ESP you might do something like:
number:
- platform: template
id: templatenumber
unit_of_measurement: "ml"
switch:
- platform: gpio
pin: ??
name: "Cal Mag Pump"
id: "calmag_pump"
on_turn_on:
- delay: !lambda 'return id(templatenumber).state * 1000;'
- switch.turn_off: calmag_pump
Not tested, but should work