@martinhjelmare
Thanks, i finally got it. I went to the example you have on home-assistant.io and removed the button and added a second actuator. Works like it should now. You are the king!
Final code for anyone whom it may help/want it.
/*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* http://www.mysensors.org/build/relay
*
*
*Holiday LED Lights MySensors Module, for MySensors v2.0
* Nothing fancy, just a two actuator (on/off) virtual switch for small
* low powred LED strings that normally run from a battery pack.
*
*
*/
#define MY_DEBUG
#define MY_RADIO_NRF24
#define MY_REPEATER_FEATURE
#define MY_NODE_ID 24 // or comment out for auto
#include <SPI.h>
#include <MySensors.h>
#define MULTI_PIN 3 // Pin that Multi-Coloured LED string is connected to
#define WHITE_PIN 5 // Pin that White LED string is connected to
#define CHILD_ID_MULTI 1 // Child ID for Multi-Coloured LED String
#define CHILD_ID_WHITE 2 // Child ID for White LED String
#define MULTI_ON 1
#define MULTI_OFF 0
#define WHITE_ON 1
#define WHITE_OFF 0
bool stateMULTI = false; // Place holders for the loop function to register nodes in Home-Assistant
bool initialValueSentMULTI = false;
bool stateWHITE = false;
bool initialValueSentWHITE = false;
MyMessage msgMULTI(CHILD_ID_MULTI, V_STATUS); //Presentation of Switch for Multi-Coloured LEDS
MyMessage msgWHITE(CHILD_ID_WHITE, V_STATUS); //Presentation of Switch for White LEDS
void setup()
{
// Make sure relays are off when starting up
digitalWrite(MULTI_PIN, MULTI_OFF);
pinMode(MULTI_PIN, OUTPUT);
digitalWrite(WHITE_PIN, WHITE_OFF);
pinMode(WHITE_PIN, OUTPUT);
}
void presentation() {
sendSketchInfo("HolidayDeskLights", "1.0");
present(CHILD_ID_MULTI, S_LIGHT);
present(CHILD_ID_WHITE, S_LIGHT);
}
void loop()
{
if (!initialValueSentMULTI) {
Serial.println("Sending initial value");
send(msgMULTI.set(stateMULTI?MULTI_ON:MULTI_OFF));
Serial.println("Requesting initial value from controller");
request(CHILD_ID_MULTI, V_STATUS);
wait(2000, C_SET, V_STATUS);
}
if (!initialValueSentWHITE) {
Serial.println("Sending initial value");
send(msgWHITE.set(stateWHITE?WHITE_ON:WHITE_OFF));
Serial.println("Requesting initial value from controller");
request(CHILD_ID_WHITE, V_STATUS);
wait(2000, C_SET, V_STATUS);
}
}
void receive(const MyMessage &message) {
if (message.isAck()) {
Serial.println("This is an ack from gateway");
}
if (message.type == V_STATUS && message.sensor == CHILD_ID_MULTI) {
if (!initialValueSentMULTI) {
Serial.println("Receiving initial value from controller");
initialValueSentMULTI = true;
}
// Change relay state
stateMULTI = (bool)message.getInt();
digitalWrite(MULTI_PIN, stateMULTI?MULTI_ON:MULTI_OFF);
send(msgMULTI.set(stateMULTI?MULTI_ON:MULTI_OFF));
}
if (message.type == V_STATUS && message.sensor == CHILD_ID_WHITE) {
if (!initialValueSentWHITE) {
Serial.println("Receiving initial value from controller");
initialValueSentWHITE = true;
}
// Change relay state
stateWHITE = (bool)message.getInt();
digitalWrite(WHITE_PIN, stateWHITE?WHITE_ON:WHITE_OFF);
send(msgWHITE.set(stateWHITE?WHITE_ON:WHITE_OFF));
}
}