Success. stole some code from a post a while ago: No concept of how efficient this is, but hey...
The MySensors Arduino library handles the wireless radio link and protocol
between your home built sensors/actuators and HA controller of choice.
The sensors forms a self healing radio network with optional repeaters. Each
repeater and gateway builds a routing tables in EEPROM which keeps track of the
network topology allowing messages to be routed to nodes.
Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
Copyright (C) 2013-2018 Sensnology AB
Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
Documentation: http://www.mysensors.org
Support Forum: http://forum.mysensors.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*******************************
REVISION HISTORY
Version 1.0 - Henrik Ekblad
DESCRIPTION
Example sketch showing how to control physical relays.
This example will remember relay state after power failure.
http://www.mysensors.org/build/relay
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_RF24
//#define MY_RADIO_NRF5_ESB
//#define MY_RADIO_RFM69
//#define MY_RADIO_RFM95
// Enable repeater functionality for this node
//#define MY_REPEATER_FEATURE
#include <MyConfig.h>
#include <MySensors.h>
#include <SPI.h>
#define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define FLOAT_SWITCH_PIN 3 //FLOAT SWITCH PIN
#define LED_GRN_PIN 7
#define LED_RED_PIN 8
#define MY_TRANSPORT_WAIT_READY_MS (3000)
#define CHILD_ID 4
#define RELAY_ON 1
#define RELAY_OFF 0
boolean lastSensorState;
unsigned long lastUpdate;
MyMessage msg(CHILD_ID, V_STATUS);
void setup()
{
pinMode(RELAY_PIN, OUTPUT);
pinMode(FLOAT_SWITCH_PIN, INPUT);
// Define LED
pinMode(LED_GRN_PIN, OUTPUT);
pinMode(LED_RED_PIN, OUTPUT);
}
void presentation()
{
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Rollermat", "3.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_BINARY);
}
void loop()
{
// LOW corresponds to the float switch being at its highest point (i.e. rollermat is clogged)
if(digitalRead(FLOAT_SWITCH_PIN) == LOW)
{
digitalWrite(RELAY_PIN, RELAY_ON); //turn on the motor
digitalWrite(LED_GRN_PIN, LOW); //turns on the Green LED
digitalWrite(LED_RED_PIN, HIGH); //turns off the Red LED
}
//otherwise the float switch is HIGH
// HIGH corresponds to the float switch being at its lowest point (i.e. rollermat is clean and water is flowing)
else
{
digitalWrite(RELAY_PIN, RELAY_OFF); //turns off the pump
digitalWrite(LED_GRN_PIN, HIGH); //turns off the Green LED
digitalWrite(LED_RED_PIN, LOW); //turns on the Red LED
}
boolean sensorState = digitalRead(FLOAT_SWITCH_PIN);
if (sensorState != lastSensorState)
{
#ifdef DEBUG
digitalWrite(FLOAT_SWITCH_PIN,sensorState? HIGH : LOW);
Serial.println(sensorState? "Motor On" : "Motor Off");
#endif
send(msg.set(sensorState?"1":"0")); // Update gateway on change of state
lastSensorState = sensorState;
}
}