create_boolean_listener()
  • 1 Minute to read

create_boolean_listener()


Article summary

Create a listener triggered when the value of one (or multiple) boolean sensor(s) go(es) into a specific logic state.

Note: This method only works with boolean sensors. Remember the types of sensors in the Gary sensors page.

Reference

Arguments

ArgumentsType
listener_namestringUnique listener identifier.
callbackcallableCallback function.
sensor_pathslistList of sensors paths, see the list of sensors.
logic_stateboolLogic state to trigger the listener.

Return

None

Exceptions

  • RayaSensorsInvalidPath
  • RayaSensorsUnknownPath
  • RayaListenerAlreadyCreated
  • RayaNeedCallback

See the complete sensors exceptions.

See the general exceptions.

Callback Arguments

Callback does not receive any arguments.

Usage example

1. Line detection

Detect a line by any of the line sensors:

async def setup(self):
    ...
    self.sensors = await self.enable_controller('sensors')
    self.sensors.create_boolean_listener(listener_name='line',
                                           callback = self.line_callback,
                                           sensor_paths = ['/line_sensor/1', '/line_sensor/2', '/line_sensor/3'],
                                           logic_state = True)
    ...
    
async def loop(self):
    # Doing other stuff
    ...
    
def line_callback(self):
        self.log.info('line detected!')

Was this article helpful?

What's Next