How to listen for a state change to greater than a given value?

I am trying to write an automation that runs my roomba once it’s recharged above a certain level. The updates from the battery_level don’t necessarily hit specific values as they are updated, so I want to write a listen_state that triggers when the battery_level attribute gets above a certain value.

Is there a way to accomplish this?

  self.listen_state(self.do_anything,"roomba_entity"

def do_anything(self, entity, attribute, old, new, kwargs):
  bat_level=float(attribute["battery_level"])
  threshold = 80
  if bat_level > threshhold:
    ... do what you want
1 Like

Oh, I see, I suppose that works. Thanks!

1 Like