MySensors template for use with HA

I’ve created a companion Arduino sketch / library to go along with the MySensors 2.x library. The companion library is designed with flexibility and inheritance to allow easy configuration of attached sensors and actuators. I.e. just tell the library you want to add a gpio output, an analog input, a PWM output, … and the library handles all the necessary code. This makes the base Arduino sketch much simpler and allows for easier configuration and programming of modules with different and varying features.

I’m midway through development and have some more features to add, but I wanted to solicit some feedback to see if there were general ideas or concepts that I am missing. Note: I’m not a professional programmer and am learning some of this as I go!

The software is specifically designed for (and only tested with) the Home Assistant controller.

Github here: https://github.com/brahmafear/MySensors_Node. Best starting point is the Arduino sketch listed in the examples folder.

Example of a full Arduino sketch with 4 sensors/actuators using this library:

#define MY_RADIO_NRF24

#include <SPI.h>
#include <MySensors.h>
#include "MySensors_Node.h"
  
MySensors_Node node("Sample", "0.01");

void presentation() {

  MySensors_Node_Sensor_Gpio_Out nsgo( 11, "Simple LED 1", 5, true );
  node.add_sensor( &nsgo );

  node.add_sensor(  new MySensors_Node_Sensor_Gpio_In( 13, "Simple Motion", 2, true, INPUT_PULLUP, 500 ) );
  node.add_sensor(  new MySensors_Node_Sensor_Analog_In( 14, "Analog In", A0, true, 1024, 10000 ) );
  node.add_sensor(  new MySensors_Node_Sensor_Pwm( 15, "PWM LED", 6, true, true, 255 ) );

  node.present();
}

void receive( const MyMessage &msg ) {
  node.receive( msg );
}


void setup() {
  node.setup();
}

void loop() {
  node.loop();
}

Cheers.

1 Like

You might want to consider posting this under “Share my projects”.