I want change state for the LEDS but they both lights when i Press on in Domoticz.
How to solve the last stage with if (message.type == V_STATUS) // Change relay state
If command A = Led 1 lights or command B = Led 2 Lights.
Best regards!
/**
* 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-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/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.
*
*******************************
*
* DESCRIPTION
*
* Simple binary switch example
* Connect button or door/window reed switch between
* digitial I/O pin 3 (BUTTON_PIN below) and GND.
* http://www.mysensors.org/build/binary
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_RF24
//#define MY_RADIO_RFM69
#include <MySensors.h>
#include <Bounce2.h>
#define CHILD_ID_1 1
#define CHILD_ID_2 2
#define CHILD_ID_3 3
#define CHILD_ID_4 4
#define CHILD_ID_5 5 //LED KNAPP OUTPUT
#define CHILD_ID_6 6 //LED KNAPP OUTPUT
#define LED_PIN_Channel_1 3 // Relay
#define LED_PIN_Channel_2 4 // Relay
#define BUTTON_PIN_Channel_1 5
#define BUTTON_PIN_Channel_1 5 // Arduino Digital I/O pin for button/reed switch
#define BUTTON_PIN_Channel_2 6
#define BUTTON_PIN_Channel_3 7
#define BUTTON_PIN_Channel_4 8
#define MY_REPEATER_FEATURE
#define MY_DEFAULT_LED_BLINK_PERIOD 300
#define MY_DEFAULT_TX_LED_PIN A0
#define MY_DEFAULT_RX_LED_PIN A1
// RELÄ LED
#define RELAY_1_ON 1
#define RELAY_2_ON 1
#define RELAY_1_OFF 0
#define RELAY_2_OFF 0
bool state_1; // RELÄ 1
bool state_2; // RELÄ 2
Bounce debouncer_1 = Bounce();
Bounce debouncer_2 = Bounce();
Bounce debouncer_3 = Bounce();
Bounce debouncer_4 = Bounce();
int oldValue_1=-1;
int oldValue_2=-1;
int oldValue_3=-1;
int oldValue_4=-1;
// Change to V_LIGHT if you use S_LIGHT in presentation below
MyMessage msg1(CHILD_ID_1, V_TRIPPED);
MyMessage msg2(CHILD_ID_2, V_TRIPPED);
MyMessage msg3(CHILD_ID_3, V_TRIPPED);
MyMessage msg4(CHILD_ID_4, V_TRIPPED);
MyMessage msg5(CHILD_ID_5, V_STATUS); //LED
MyMessage msg6(CHILD_ID_6, V_STATUS); //LED
void setup()
{
// Setup the button
// Activate internal pull-up
// After setting up the button, setup debouncer
pinMode(BUTTON_PIN_Channel_1,INPUT);
pinMode(BUTTON_PIN_Channel_2,INPUT);
pinMode(BUTTON_PIN_Channel_3,INPUT);
pinMode(BUTTON_PIN_Channel_4,INPUT);
// RELÄ
pinMode(LED_PIN_Channel_1, OUTPUT);
pinMode(LED_PIN_Channel_2, OUTPUT);
pinMode(A0, OUTPUT); // RX TX Använda Analog pin som output
pinMode(A1, OUTPUT); // RX TX
digitalWrite(LED_PIN_Channel_1, RELAY_1_OFF);
digitalWrite(LED_PIN_Channel_2, RELAY_2_OFF);
// Minne från EEPROM
state_1 = loadState(CHILD_ID_5);
digitalWrite(LED_PIN_Channel_1, state_1?RELAY_1_ON:RELAY_1_OFF);
state_2 = loadState(CHILD_ID_6);
digitalWrite(LED_PIN_Channel_2, state_2?RELAY_2_ON:RELAY_2_OFF);
digitalWrite(BUTTON_PIN_Channel_1,LOW);
digitalWrite(BUTTON_PIN_Channel_2,LOW);
digitalWrite(BUTTON_PIN_Channel_3,LOW);
digitalWrite(BUTTON_PIN_Channel_4,LOW);
debouncer_1.attach(BUTTON_PIN_Channel_1);
debouncer_2.attach(BUTTON_PIN_Channel_2);
debouncer_3.attach(BUTTON_PIN_Channel_3);
debouncer_4.attach(BUTTON_PIN_Channel_4);
debouncer_1.interval(5);
debouncer_2.interval(5);
debouncer_3.interval(5);
debouncer_4.interval(5);
}
void presentation() {
// Register binary input sensor to gw (they will be created as child devices)
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
// Send the sketch version information to the gateway and Controller
sendSketchInfo(F("Bosses LEKSAK"), F("1.1"));
present(CHILD_ID_1, S_DOOR);
present(CHILD_ID_2, S_DOOR);
present(CHILD_ID_3, S_DOOR);
present(CHILD_ID_4, S_DOOR);
present(CHILD_ID_5, S_BINARY);
present(CHILD_ID_6, S_BINARY);
}
// Check if digital input has changed and send in new value
void loop()
{
debouncer_1.update();
debouncer_2.update();
debouncer_3.update();
debouncer_4.update();
// Get the update value
int value_1 = debouncer_1.read();
int value_2 = debouncer_2.read();
int value_3 = debouncer_3.read();
int value_4 = debouncer_4.read();
if (value_1 != oldValue_1) {
// Send in the new value
send(msg1.set(value_1==HIGH ? 1 : 0));
oldValue_1 = value_1; }
if (value_2 != oldValue_2) {
// Send in the new value
send(msg2.set(value_2==HIGH ? 1 : 0));
oldValue_2 = value_2; }
if (value_3 != oldValue_3) {
// Send in the new value
send(msg3.set(value_3==HIGH ? 1 : 0));
oldValue_3 = value_3; }
if (value_4 != oldValue_4) {
// Send in the new value
send(msg4.set(value_4==HIGH ? 1 : 0));
oldValue_4 = value_4; }
}
void receive(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.isAck()) {
Serial.println("This is an ack from gateway");
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
if (message.type == V_STATUS) {
// Change relay state
state_1 = message.getBool();
digitalWrite(LED_PIN_Channel_1, state_1?RELAY_1_ON:RELAY_1_OFF);
// Store state in eeprom
saveState(CHILD_ID_5, state_1);
// Write some debug info
Serial.print("Incoming change for sensor: STATE 1");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
if (message.type == V_STATUS) {
// Change relay state
state_2 = message.getBool();
digitalWrite(LED_PIN_Channel_2, state_2?RELAY_2_ON:RELAY_2_OFF);
// Store state in eeprom
saveState(CHILD_ID_6, state_2);
// Write some debug info
Serial.print("Incoming change for sensor: STATE 2");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}