@hek said:
You can disable this behaviour by defining:
#define MY_TRANSPORT_DONT_CARE_MODE #define MY_PARENT_NODE_ID 0
sorry for the ridiculous question but I have to enter into a sketch? or MyConfig.h?
@hek said:
You can disable this behaviour by defining:
#define MY_TRANSPORT_DONT_CARE_MODE #define MY_PARENT_NODE_ID 0
sorry for the ridiculous question but I have to enter into a sketch? or MyConfig.h?
@mfalkvidd
Better start from the beginning.
What I need to change in the code or configurations (MyConfig.h) to work the physical switch when the failure of the gateway.
Thank You
@mfalkvidd
I would like to control physical switch even if the gateway is unavailable (use domoticz and this project https://www.openhardware.io/view/77/AC-DC-double-solid-state-relay-module).
Now physical switch works only when is communicating with the gateway.
Thank You
// Example sketch fΓΆr a "light switch" where you can control light or something
// else from both vera and a local physical button (connected between digital
// pin 3 and GND).
// This node also works as a repeader for other nodes
#define MY_RADIO_NRF24
#include <MySensors.h>
#include <SPI.h>
#include <Bounce2.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define RELAY_PIN 3 // Arduino Digital I/O pin number for relay
#define RELAY_PIN_2 5
#define BUTTON_PIN 4 // Arduino Digital I/O pin number for button
#define BUTTON_PIN_2 7
#define ONE_WIRE_BUS 8
#define CHILD_DSB_ID 13
#define CHILD_ID_2 12
#define CHILD_ID 11 // Id of the sensor child
#define RELAY_ON 1
#define RELAY_OFF 0
Bounce debouncer = Bounce();
int oldValue = 0;
bool state;
Bounce debouncer2 = Bounce();
int oldValue2 = 0;
bool state2;
MyMessage msg(CHILD_ID, V_LIGHT);
MyMessage msg2(CHILD_ID_2, V_LIGHT);
MyMessage msgTemp(CHILD_DSB_ID, V_TEMP);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature.
void presentation() {
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Double Relay & Button", "0.2");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_LIGHT);
present(CHILD_ID_2, S_LIGHT);
present(CHILD_DSB_ID, S_TEMP);
}
void setup()
{
sensors.begin();
sensors.setWaitForConversion(false);
// Setup the button
pinMode(BUTTON_PIN, INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN, HIGH);
// Setup the button
pinMode(BUTTON_PIN_2, INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN_2, HIGH);
// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
debouncer2.attach(BUTTON_PIN_2);
debouncer2.interval(5);
// Make sure relays are off when starting up
digitalWrite(RELAY_PIN, RELAY_OFF);
// Then set relay pins in output mode
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN_2, RELAY_OFF);
// Then set relay pins in output mode
pinMode(RELAY_PIN_2, OUTPUT);
// Set relay to last known state (using eeprom storage)
state = loadState(CHILD_ID);
digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF);
state2 = loadState(CHILD_ID_2);
digitalWrite(RELAY_PIN_2, state2 ? RELAY_ON : RELAY_OFF);
}
/*
* Example on how to asynchronously check for new messages from gw
*/
void loop()
{
static float prevTemp = 0;
debouncer.update();
debouncer2.update();
// Get the update value
int value = debouncer.read();
int value2 = debouncer2.read();
if (value != oldValue) {
send(msg.set(state ? false : true), true); // Send new state and request ack back
}
oldValue = value;
if (value2 != oldValue2) {
send(msg2.set(state2 ? false : true), true); // Send new state and request ack back
}
oldValue2 = value2;
// Fetch temperatures from Dallas sensors
sensors.requestTemperatures();
// Fetch and round temperature to one decimal
float temperature = static_cast<float>(static_cast<int>(sensors.getTempCByIndex(0) * 10.f)) / 10.f;
if (temperature != -127.00f && temperature != 85.00f && prevTemp != temperature) {
// Send in the new temperature
send(msgTemp.set(temperature, 1));
Serial.print("Sent temperature: ");
Serial.println(temperature);
prevTemp = temperature;
}
}
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");
}
if (message.type == V_LIGHT && message.sensor == 11) {
// Change relay state
state = message.getBool();
digitalWrite(RELAY_PIN, state ? RELAY_ON : RELAY_OFF);
// Store state in eeprom
saveState(CHILD_ID, state);
}
else if (message.type == V_LIGHT && message.sensor == 12) {
state2 = message.getBool();
digitalWrite(RELAY_PIN_2, state2 ? RELAY_ON : RELAY_OFF);
// Store state in eeprom
saveState(CHILD_ID_2, state2);
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
Still is problem with physical button when gateway is not responsible.( i can not off and on the lights )
For example, when a server domoticz failure.
Hello, two month ago i asked question
In this topic: https://forum.mysensors.org/topic/3671/ac-dc-double-solid-state-relay-module/93
"Hello.
I would like to ask whether it is normal that the switch does not work if the server domoticz off? I want to use the switch only crash server now i cant"
And i got a reply from @hek it will be in the new library.(post 90)
Now i see 2.1.0 , and i have question now it is work?
Thank You
@tonnerre33
Avesome photogallery
whose sketch you used? because I have a problem with phisycal switches if I use sketch of Nca78 (I wrote about this earlier)
Hello.
I tried to upload my two boards ( arduino pro mini 8Mhz , 3,3 V ) modified sketches but returned to sketch Nca78 (with DS18B20), unfortunately, does not operate a physical switch. Sometimes phisical switch changes state in domoticz ( not every time ) but relays do not change state.
Switching on and switching off the lights of domoticz changes state relay without a problem.
What could be wrong ?
It possible implement this option in mysensors 2.0 ?
@hek said:
You can disable this behaviour by defining:
#define MY_TRANSPORT_DONT_CARE_MODE #define MY_PARENT_NODE_ID 0
sorry for the ridiculous question but I have to enter into a sketch? or MyConfig.h?
Thanx for the answers
This is not good news from the switch does not work without a server. Mr.const, Do you use esp8266 in domoticz to control the light?
edit: hek, I not noticed your post.
What changes adding this?
#define MY_TRANSPORT_DONT_CARE_MODE
#define MY_PARENT_NODE_ID 0```