PymateIO-remote-control

From pymate.io wiki
Jump to navigation Jump to search


Abstract

The remote control is the most widespread usage in automation.

Click once and lights turn on, click again then the lights shut-off.

Remote-control-example.png

Wiring

Here a typical wiring;

  • Push Buttons are connected to IN3 (connected in parallels)
  • Stairs lights are controlled by OUT5 (via a relay)

Remote-control-wiring.png

Script

Here an commented example of main.py script that can be used with PymateIO Core.

The TimeoutTimer class is used to start a Timeout of 2 seconds when the button is pressed.

Any additional button press will be ignored within that period of time.

Once the 2 seconds expired, a new button press will be accepted.

from machine import Pin
from pymate import TimeoutTimer
from pymate.pymateio import PymateIO

FORBID_SEC = 2

button = PymateIO( "In3", Pin.IN )
relay = PymateIO( "Out5", Pin.OUT )
relay.write( 0 )

# Start a timer that expires immediately for
# coding convenience
t = TimeoutTimer(0.1) 

while True:
	# Button Pressed and
	# Outside of forbidden period
	if button.read() and t.expired:
		# Invert Output State
		relay.write( not(relay.read()) )
		# Restart a new forbidden period
		t.set( FORBID_SEC )

PymateIO all right reserved © 2026 - Written by MCHobby for PymateIO