that totally worked. thanks!
Now how do I use a binary sensor to trigger my while loop of “on_boot”? I’ve tried referencing the ID as well as using a lambda and setting globals, all to no avail. I just cant recognize its on/true state. It works outside of on_boot. I check the same sensor in a binary_sensor section using the same
condition:
- binary_sensor.is_on: p5z
and it works fine. but not here:
on_boot:
priority: -100.0
then:
- delay: 20s
- logger.log:
format: "In on_boot: p5z =%1f | auger_off_timez = %.1f | auger_on_timez = %.1f "
args: [ 'id(p5z).state', 'id(auger_off_timez).state', 'id(auger_on_timez).state' ]
- while:
condition:
# lambda: |-
# if (id(p5z)) {
# return true;
# } else {
# return false;
# }
- binary_sensor.is_on: p5z
then:
- logger.log: "P5 active.in WHILE LOOP "
its always reporting a value of 0.0 in my logger statement, even when it is TRUE:
format: "In on_boot: p5z =%1f | auger_off_timez = %.1f | auger_on_timez = %.1f "
args: [ 'id(p5z).state', 'id(auger_off_timez).state', 'id(auger_on_timez).state' ]
[10:35:31][D][main:318]: In on_boot: p5z =0.000000 | auger_off_timez = 10.5 | auger_on_timez = 1.0
The full sections:
on_boot:
priority: -100.0
then:
- delay: 20s
- logger.log:
format: "In on_boot: p5z =%1f | auger_off_timez = %.1f | auger_on_timez = %.1f "
args: [ 'id(p5z).state', 'id(auger_off_timez).state', 'id(auger_on_timez).state' ]
- while:
condition:
# lambda: |-
# if (id(p5z)) {
# return true;
# } else {
# return false;
# }
- binary_sensor.is_on: p5z. <<<----THIS DOES NOT WORK
then:
- logger.log: "P5 active.in WHILE LOOP "
- switch.turn_on: auger_output_to_optoisolator
- logger.log:
format: "on_boot in WHILE auger_ON_timez Delay Value: %.1f .1f"
args: [ 'id(auger_on_timez).state']
- delay: !lambda "return id(auger_on_timez).state * 1000;"
globals:
- id: g_p5
type: bool
initial_value: 'false'
binary_sensor:
- platform: homeassistant
id: p5z
entity_id: input_boolean.p5
on_state: # WHEN STATE IS PUBLISHED
then:
- globals.set:
id: g_p5
value: !lambda 'return bool(x);'
#
- platform: gpio
pin: GPIO4
id: esph_house_auger_sensor_from_mcu
name: "esph House Auger Sensor from MCU" #pinAuger signal from MCU, goes low when motor is running
filters:
- invert:
# This is the code that will run when the binary sensor detects that the Auger motor needs to be turned off
on_state:
then:
- logger.log:
format: "GPIO4 on_state: changed! p5z =%1f | auger_off_timez = %.1f | auger_on_timez = %.1f "
args: [ 'id(p5z).state', 'id(auger_off_timez).state', 'id(auger_on_timez).state' ]
# Turn on the Auger motor
- if:
condition:
and:
- binary_sensor.is_off: p5z. <<<<----THIS WORKS FINE.
- binary_sensor.is_off: esph_house_auger_sensor_from_mcu
then:
- switch.turn_off: auger_output_to_optoisolator
EDIT: Nothing I tried worked so I moved it out of on_boot and into the binary sensor on_state trigger which works perfectly. VERY STRANGE. I battled this for almost a day.
binary_sensor:
- platform: homeassistant
id: p5z
entity_id: input_boolean.p5
on_state: # WHEN STATE IS PUBLISHED
then:
# - logger.log: "P5 state changed"
- while:
condition:
- binary_sensor.is_on: p5z
then:
- logger.log: "P5 active.in WHILE LOOP "
- switch.turn_on: auger_output_to_optoisolator
- logger.log:
format: "on_boot in WHILE auger_ON_timez Delay Value: %.1f .1f"
args: [ 'id(auger_on_timez).state']
- delay: !lambda "return id(auger_on_timez).state * 1000;"
#
- switch.turn_off: auger_output_to_optoisolator
- logger.log:
format: "on_boot in WHILE auger_OFF_timez Delay Value: %.1f .1f"
args: [ 'id(auger_off_timez).state']
- delay: !lambda "return id(auger_off_timez).state * 1000;"
- logger.log: "P5 active Auger OFF after auger_off_timez"