Not even just using the example relay code works. destined output pin is permanently on (HIGH) and activating the switch in controller has no effect on it.
Help please....
Not even just using the example relay code works. destined output pin is permanently on (HIGH) and activating the switch in controller has no effect on it.
Help please....
So trying to activate a switch (by reading the state of a binary value) does not seem to be working.
With this code, my 2 fake doors show up in Home Assistant, but my S_BINARY does not, despite presenting it. Am I missing something?
#include <MySensors.h>
#define OPEN_DOORONE 1
#define CLOSE_DOORONE 0
#define CLOSE_DOORTWO 0
#define OPEN_DOORTWO 1
#define DOORONE_ID 1
#define DOORTWO_ID 2
#define LEDSWITCH_ID 3
#define RELAY_PIN 11
#define RELAY_ON 1
#define RELAY_OFF 0
MyMessage msg1(DOORONE_ID, V_TRIPPED);
MyMessage msg2(DOORTWO_ID, V_TRIPPED);
uint8_t value_doorone = OPEN_DOORONE;
uint8_t value_doortwo = OPEN_DOORTWO;
bool state;
void before()
{
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, RELAY_OFF);
}
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors
sendSketchInfo("JERTestDoorsss", "1.0");
present(DOORONE_ID, S_DOOR);
present(DOORTWO_ID, S_DOOR);
present(LEDSWITCH_ID, S_BINARY);
}
void loop()
{
// Send locally attached sensor data here
value_doorone = value_doorone == OPEN_DOORONE ? CLOSE_DOORONE : OPEN_DOORONE;
send(msg1.set(value_doorone));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
}
void receive(const MyMessage &message)
{
if (message.type == V_STATUS)
{
state = message.getBool();
digitalWrite(RELAY_PIN, state?RELAY_ON:RELAY_OFF);
}
}```
Thanks! I have successfully created TWO dummy doors now! lol
This was instructive to understanding how the presentation of multiple local sensors looks like, since most examples show only one.
My next task is to learn how to control a switch (ie two way communication)
Here it is for anyone else for whom this might be helpful:
#include <MySensors.h>
#define OPEN_DOORONE 1
#define CLOSE_DOORONE 0
#define CLOSE_DOORTWO 0
#define OPEN_DOORTWO 1
#define DOORONE_ID 1
#define DOORTWO_ID 2
MyMessage msg1(DOORONE_ID, V_TRIPPED);
MyMessage msg2(DOORTWO_ID, V_TRIPPED);
uint8_t value_doorone = OPEN_DOORONE;
uint8_t value_doortwo = OPEN_DOORTWO;
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors
sendSketchInfo("JERTestDoorsss", "1.0");
present(DOORONE_ID, S_DOOR);
present(DOORTWO_ID, S_DOOR);
}
void loop()
{
// Send locally attached sensor data here
value_doorone = value_doorone == OPEN_DOORONE ? CLOSE_DOORONE : OPEN_DOORONE;
send(msg1.set(value_doorone));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
value_doortwo = value_doortwo == OPEN_DOORTWO ? CLOSE_DOORTWO : OPEN_DOORTWO;
send(msg2.set(value_doortwo));
sleep(2000);
}
Could I bother you to ask:
Now that I've made my fake door open and close a bunch, is there an example that shows the initializing and presenting of multiple local sensors (local to the gateway) and what that looks like?
I tried to simply put another present(2, S_DOOR)
as child 2 and another door but.. I dont think HA see's it. Am i approaching this wrong?
Also, does sendSketchInfo
have to be done for every sensor local to the gateway or is it just presenting the one name under which all the sensors will be "children" ?
Any help would be appreciated.
Thank you so much! I've got the example "door open/door close" dummy sensor sketch succesfully talking to my HASS.IO.
I'm literally going to type this sentence so that people might find this later in a forum search if they are looking like I was for an answer: direct to USB, wired USB, hass.io arduino mega, serial gateway no radio, local sensor no radio serial gateway usb.
Sorry for that but i was tearing my hair out looking for this simple solution and could not find it.
The trick is to comment out the RF radios (all of them). It wasn't clear to me that blanking out all the radios meant it would still do serial. The part to config on the HASS seemed clear to me (/dev/ttyACM0) but since I couldn't get the gateway part to work I had no idea if that was even right.
Again, thanks so much.
I swear I've spend hours pouring over the documentation and the forums, but I simply cannot find a straight or working answer for this.
I'd like to use an Arduino Mega as both a gateway AND use its pins as sensors/switches, and I'd like to connect it directly to a Raspberry Pi 3 B+ running Home Assistant (hass.io) and use Home Assistant as the controller.
I know 98% of peoples uses cases are wireless, so they involve radios, but mine is all wired and I'd like to do it as I describe.
As far as I can tell, this involves Serial communication somehow, but its not exactly clear either how to initialize MySensors gateway sketch to communicate over the USB port much less how that is accessed on the USB host device.
Can someone please point me in the right direction for what I'd like to do? Any help would be greatly appreciated.