Use binary sensor in Esphome on_press

Real world use case: I want to use the state of this

binary_sensor:
  - platform: template
    name: DFPlayer State
    lambda: |-
      return id(dfplayerState).is_playing();

esphome sensor in the condition of an Esphome on_press event - is it possible please?

Basically I want the on_press to do something ONLY if the binary_sensor is not β€˜on’

make sense?!

thanks!

So say you have a button on gpio12

binary_sensor:
   platform: gpio
   pin: gpio12
   on_press:
     then:
       lambda: !lambda |-
         if id(dfplayerState).is_playing() {
           do something;
         } else {
           do something else;
         }  
1 Like

Oh thank you! Brilliant! :smiley: