Hi,
I have no programming background and I am really struggling with esphome lambdas.
What I want to do:
This is part of my irrigation project - in HA I want to be able to define for how long drip irrigation should be on for - for that I want to use input number helper, and use that in esphome as a switch delay value
This is what I have so far:
sensor:
- platform: homeassistant
name: Irrigation Duration
entity_id: input_number.esphome_irrigation_delay_duration
id: ha_irrigation_duration
- platform: template
name: Delay Minutes
id: delay_minutes
lambda: |-
if (id(ha_irrigation_duration).state == 15.0) {
return 15.0 * 60;
} else {
return id(ha_irrigation_duration).state * 60;
}
switch:
- platform: gpio
name: "FlowerBed"
id: relay1
pin: 19
on_turn_on:
then:
- lambda: |-
// Turn off the relay after the delay
id(relay1).turn_off();
// Delay the turn off of the relay
delay(id(delay_minutes).state);
this compiles fine but it seems to crash my nodemcu32 device: here is the log file:
[10:20:35][C][homeassistant.sensor:030]: Homeassistant Sensor 'Irrigation Duration'
[10:20:35][C][homeassistant.sensor:030]: State Class: ''
[10:20:35][C][homeassistant.sensor:030]: Unit of Measurement: ''
[10:20:35][C][homeassistant.sensor:030]: Accuracy Decimals: 1
[10:20:35][C][homeassistant.sensor:031]: Entity ID: 'input_number.esphome_irrigation_delay_duration'
[10:20:56][D][homeassistant.sensor:024]: 'input_number.esphome_irrigation_delay_duration': Got state 2.00
[10:20:56][D][sensor:127]: 'Irrigation Duration': Sending state 2.00000 with 1 decimals of accuracy
[10:21:05][D][switch:013]: 'FlowerBed' Turning ON.
[10:21:05][D][switch:056]: 'FlowerBed': Sending state ON
[10:21:05][D][switch:017]: 'FlowerBed' Turning OFF.
[10:21:05][D][switch:056]: 'FlowerBed': Sending state OFF
WARNING 192.168.1.7: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for 192.168.1.7
WARNING Disconnected from API
INFO Successfully connected to 192.168.1.7
The device starts OK, when I change the value of the input number in HA that is being picked up by the device, when I turn the switch On in HA I can hear the relay click and 1-2 seconds later the switch becomes greyed out in HA and the device reboots.
Any ideas what is going on here and how to fix this?
Thanks