I’m really struggling with the learning curve on this stuff. If this was a PLC, i’d be done in 5 seconds. If there’s a getting started lab book on writing custom code I’m not finding it.
I essentially have a device that will be triggered by a pressure sensor from i2c bus, but for now I’d just like to get it working with a gpio input. I’d like it to retain last entered setpoint values & not rely on HA automations or scripts.
On_Time_Setpoint INT Adjustable via HA
Off_Time_Setpoint INT Adjustable via HA
So what you want is for the ESP to use values from HA to know what the setpoints are, so read this. You can create input_numbers in HA and use those as outlined in the link. Then create the automation to control your GPIO in ESPhome on the device. It will still need a connection to HA to get those setpoints but the automation is done without HA.
No need to import input numbers form home assistant as sensors. Numbers can be created on the ESP device now. Template Number — ESPHome just don’t forget to set the restore_value to true or they reset after esp device restart.
Awesome! Thank you for the extra info. number: does exactly what I was hoping. Here’s where I’m currently stuck. The While loop logic is my current hangup. I don’t know where or how to add this. I’ve tried various methods of adding it under my spdx sensor but it always complains when using “on_value” you can’t have a while loop. I’ve also tried using on_state but that’s not a valid argument for a sensor.
Are you quoting your yaml when posting? The indentation appears wrong - but it’s hard to tell. Use the “preformatted text” tags - shown as </> in the posting toolbar.
The code was correct in my .yaml and not related to the issues I’m seeing was what I was referencing. I’ve edited my original coded post to fix the issue. Thank you for pointing out the errors of my ways.
The automation goes in the sensor that would trigger the action - in an on_value: block or similar - - or if you want it checked at a regular interval then in a time block:
That’s what I’m trying to figure out. Where do I put it and what notation of on_… I’ve tried something similar to these and all have various errors and won’t compile.
Outside of the While: loop I’m trying, I was able to get seconds: to kind of work. I want the delays adjustable. I haven’t found a way to append the ‘s’ notation at the end of the number objects use in HA to adjust these delays.
After talking with a few others via discord this has been sorted out. While my case is turning off and on a home scent diffuser triggered by static pressure differential, this same automation can be used for any scenario where an analog input is required to cycle an output on and off. Once I complete the final install I’ll post my hardware design and practical use case. I’m not too happy with the size of tubing on the differential pressure sensor so I’m looking at alternatives.
Functional description:
Examine analog static pressure differential sensor to determine if HVAC is running with a binary sensor object. As configured in included yaml "If differential pressure is greater than HVAC_running_setpoint, then HVAC is running. Using “HVAC running” binary sensor a script is triggered that WHILE TRUE turn relay on for XX Seconds (HA Adjustable via diffuser_on_setpoint) THEN turn relay off for XX Seconds (HA Adjustable via diffuser_off_setpoint)
Setpoints: (Rename as you see fit, located in the NUMBERS section of the yaml)
HVAC_running_setpoint: Used as the trigger to start the automation. Adjustable via HA rather than hard coded to make initial setup easier than multiple reflashes of esp32 device.
diffuser_on_setpoint: Used as the duration of the ON action trigger. Configured in seconds. Adjustable via HA.
diffuser_off_setpoint: Used as the duration of the OFF action trigger. Configured in seconds. Adjustable via HA.