sensor.hcsr04#

class platypush.plugins.sensor.hcsr04.SensorHcsr04Plugin(*_, **__)[source]#

Bases: GpioPlugin, SensorPlugin

You can use this plugin to interact with a distance sensor on your Raspberry Pi. It’s been tested with a HC-SR04 ultrasound sensor, but it should be compatible with any GPIO-compatible sensor that relies on the same trigger-and-echo principle.

Requires:

  • RPi.GPIO (pip install RPi.GPIO)

Triggers:

__init__(trigger_pin: int, echo_pin: int, poll_interval: float = 0.25, timeout: float = 2.0, warmup_time: float = 2.0, *args, **kwargs)[source]#
Parameters:
  • trigger_pin – GPIO PIN where you connected your sensor trigger PIN (the one that triggers the sensor to perform a measurement).

  • echo_pin – GPIO PIN where you connected your sensor echo PIN (the one that will listen for the signal to bounce back and therefore trigger the distance calculation).

  • timeout – The echo-wait will terminate and the plugin will return null if no echo has been received after this time (default: 1 second).

  • warmup_time – Number of seconds that should be waited on plugin instantiation for the sensor to be ready (default: 2 seconds).

get_measurement(*_, **__) float | None[source]#
Returns:

Distance measurement as a scalar (in mm):

stop()[source]#

Stop the plugin.

transform_entities(entities: float | None | Collection[float | None]) List[DistanceSensor][source]#

This method takes a list of entities in any (plugin-specific) format and converts them into a standardized collection of Entity objects. Since this method is called by publish_entities() before entity updates are published, you may usually want to extend it to pre-process the entities managed by your extension into the standard format before they are stored and published to all the consumers.