create_boolean_listener()
- 1 Minute to read
create_boolean_listener()
- 1 Minute to read
Article summary
Did you find this summary helpful?
Thank you for your feedback
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
Arguments | Type | |
---|---|---|
listener_name | string | Unique listener identifier. |
callback | callable | Callback function. |
sensor_paths | list | List of sensors paths, see the list of sensors. |
logic_state | bool | Logic 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?