I setup a slider in HA with a range from 1-10 that gets passed to my esphome device. The variable in esphome updates each time a switch is pressed as the motor rotates. I’d like to compare the two values so when they match, the motor is turned off. I’ve been trying with a lambda, but have had no luck. The lambda below is my latest iteration. When I turn on the switch it runs thru immediately and turns off the motor, resets the variable to 0 and turns off the switch, ignoring anything in the lambda. Which I assume is formatted wrong.
switch:
- platform: template
name: "Feed on/off"
id: molly_switch
restore_state: true
turn_on_action:
- switch.template.publish:
id: molly_switch
state: ON
- switch.turn_on:
id: feeder
- if:
condition:
- lambda: |-
if ((id(num_clicks) = (id("feed_molly"))));{
return true;
}
then:
- delay: 5s
- switch.turn_off:
id: feeder
- delay: 3s
- lambda: |-
id(num_clicks) = 0;
- switch.template.publish:
id: molly_switch
state: OFF
These are the sensors.
Sent From Home Assistant to ESPHome:
sensor:
- platform: homeassistant
name: "feed molly"
entity_id: sensor.feed_volume_molly
Variable in ESPHome:
globals:
- id: num_clicks
type: int
restore_value: yes
initial_value: '0'