Requesting for help building traffic light led module node
-
Hi!
I'm trying to build a traffic light led module node on a arduino pro mini 5v. I am currently using a temperature/humidity node without a problem with raspberry pi ethernet gateway.Below is the sketch I'm working on. Its function is only to toggle in home assistant. When uploaded, it seems to be communicating with the gateway but doesn't show up in home assistant.
I'd like to know if there's something wrong with the sketch.
Thanks in advance!--sketch--
#define MY_DEBUG
#define MY_RADIO_RF24
#define MY_NODE_ID 16
#define MY_RF24_PA_LEVEL RF24_PA_LOW#include <MySensors.h>
#define CHILD_ID_GREEN 1
#define CHILD_ID_YELLOW 2
#define CHILD_ID_RED 3#define GREEN_PIN 3
#define YELLOW_PIN 4
#define RED_PIN 5bool greenState = false;
bool yellowState = false;
bool redState = false;MyMessage msgGreen(CHILD_ID_GREEN, V_LIGHT);
MyMessage msgYellow(CHILD_ID_YELLOW, V_LIGHT);
MyMessage msgRed(CHILD_ID_RED, V_LIGHT);void setup() {
Serial.begin(115200);
pinMode(GREEN_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
wait(200);
}void presentation() {
// Initialize the MySensors communication
sendSketchInfo("Traffic Light Node", "1.0");
present(CHILD_ID_GREEN, S_LIGHT);
present(CHILD_ID_YELLOW, S_LIGHT);
present(CHILD_ID_RED, S_LIGHT);
}void loop() {
}
void receive(const MyMessage &message) {
// Check which LED to control based on the message received
if (message.sensor == CHILD_ID_GREEN && message.type == V_LIGHT) {
greenState = !greenState; // Toggle the state
digitalWrite(GREEN_PIN, greenState ? HIGH : LOW); // Set the pin accordingly
send(msgGreen.set(greenState ? 1 : 0)); // Report back the new state
} else if (message.sensor == CHILD_ID_YELLOW && message.type == V_LIGHT) {
yellowState = !yellowState;
digitalWrite(YELLOW_PIN, yellowState ? HIGH : LOW);
send(msgYellow.set(yellowState ? 1 : 0));
} else if (message.sensor == CHILD_ID_RED && message.type == V_LIGHT) {
redState = !redState;
digitalWrite(RED_PIN, redState ? HIGH : LOW);
send(msgRed.set(redState ? 1 : 0));
}
}--serial communication--
2158 TSF:MSG:FPAR OK,ID=0,D=1
4065 TSM:FPAR:OK
4066 TSM:ID
4067 TSM:ID:OK
4069 TSM:UPL
4072 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
4078 TSF:MSG:READ,0-0-16,s=255,c=3,t=25,pt=1,l=1,sg=0:1
4083 TSF:MSG:PONG RECV,HP=1
4086 TSM:UPL:OK
4087 TSM:READY:ID=16,PAR=0,DIS=1
4092 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
4100 TSF:MSG:READ,0-0-16,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
4107 TSF:MSG:SEND,16-16-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
4117 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
4132 TSF:MSG:READ,0-0-16,s=255,c=3,t=6,pt=0,l=1,sg=0:M
4143 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=11,pt=0,l=18,sg=0,ft=0,st=OK:Traffic Light Node
4152 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=OK:1.0
4160 TSF:MSG:SEND,16-16-0-0,s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
4170 TSF:MSG:SEND,16-16-0-0,s=2,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
4178 TSF:MSG:SEND,16-16-0-0,s=3,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=OK:
4185 MCO:REG:REQ
4188 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=OK:2
4197 TSF:MSG:READ,0-0-16,s=255,c=3,t=27,pt=1,l=1,sg=0:1
4202 MCO:PIM:NODE REG=1
4204 MCO:BGN:STP
4406 MCO:BGN:INIT OK,TSP=1
519129 TSF:MSG:READ,0-0-255,s=255,c=3,t=20,pt=0,l=0,sg=0:
519134 TSF:MSG:BC
520131 TSF:MSG:SEND,16-16-0-0,s=255,c=3,t=21,pt=1,l=1,sg=0,ft=0,st=OK:0
-
You need to send the initial state of the sensor
https://www.home-assistant.io/integrations/mysensors/
-
@electrik Wow! You gave me a clue! Thanks!!
-
Hi airmedic79,
I think it should be temperature/humidity node design connection issue lead to not show up in home assistant,
do you have compressed files?maybe you I could do your favor for this item design,tks.BR
Jalina
-
I am sharing my sketch. Based on the sketch below, I am using this led light to show air quality status (good for green, normal for yellow and bad for red). This sketch is just a switch so you should make some automation in HA.
https://www.amazon.com/Traffic-Display-Module-Arduino-Mini-Traffic/dp/B07SZMRSDN
#define MY_DEBUG
#define MY_RADIO_RF24
#define MY_NODE_ID 16
#define MY_RF24_PA_LEVEL RF24_PA_LOW#include <MySensors.h>
#define CHILD_ID_GREEN 1
#define CHILD_ID_YELLOW 2
#define CHILD_ID_RED 3#define GREEN_PIN 3
#define YELLOW_PIN 4
#define RED_PIN 5bool greenState = false;
bool yellowState = false;
bool redState = false;MyMessage msgGreen(CHILD_ID_GREEN, V_LIGHT);
MyMessage msgYellow(CHILD_ID_YELLOW, V_LIGHT);
MyMessage msgRed(CHILD_ID_RED, V_LIGHT);void setup() {
Serial.begin(115200);
pinMode(GREEN_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(RED_PIN, OUTPUT);
wait(200);
}void presentation() {
// Initialize the MySensors communication
sendSketchInfo("Traffic Light Node", "1.0");
present(CHILD_ID_GREEN, S_LIGHT);
present(CHILD_ID_YELLOW, S_LIGHT);
present(CHILD_ID_RED, S_LIGHT);
}void loop() {
// Send initial values of the LEDs to the controller
send(msgGreen.set(greenState ? 1 : 0));
send(msgYellow.set(yellowState ? 1 : 0));
send(msgRed.set(redState ? 1 : 0));// Other tasks in the loop if needed
// ...// Add a delay to control how often the initial values are sent
delay(5000); // Send initial values every 5 seconds (adjust as needed)
}void receive(const MyMessage &message) {
// Check which LED to control based on the message received
if (message.sensor == CHILD_ID_GREEN && message.type == V_LIGHT) {
greenState = !greenState; // Toggle the state
digitalWrite(GREEN_PIN, greenState ? HIGH : LOW); // Set the pin accordingly
send(msgGreen.set(greenState ? 1 : 0)); // Report back the new state
} else if (message.sensor == CHILD_ID_YELLOW && message.type == V_LIGHT) {
yellowState = !yellowState;
digitalWrite(YELLOW_PIN, yellowState ? HIGH : LOW);
send(msgYellow.set(yellowState ? 1 : 0));
} else if (message.sensor == CHILD_ID_RED && message.type == V_LIGHT) {
redState = !redState;
digitalWrite(RED_PIN, redState ? HIGH : LOW);
send(msgRed.set(redState ? 1 : 0));
}
}