I'm very interested by your setup. It has been a shame to have some low voltage power in order to measure power consumption
I hope you can display something soon.
Regards,
@Knightan
I believe that your problem may be related to this block of code. See my thoughts as comments....
if (message.type == V_STATUS) { //This is true for all messages received
// Change relay state
state_1 = message.getBool(); //This sets state for state_1 to the received value.
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(); //This sets state for state_2 to the received value.
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());
}
It seems to me that state_1 = message.getBool(); AND state_2 = message.getBool(). So they both get set to the incoming value.
I think you need to not set both to the same value and instead differentiate them to unique values. I could be wrong as I have not had chance to do anything related to mysensors for a long time now - I also don't use Domoticz.
Have a look at the code on this page, it might help you a lot.... https://www.mysensors.org/build/relay
@kalina, Thanks. So it will not work for my configuration. Wall switch (push button) is already installed. No possibilities to draw more electrical wires.
Moreover, if i put the board near the light, i have just the Neutral and the return wire from the wall switch. No Live wire to power on the mysensors board.
I think in my ase the best way is to manage everything in my garage in the electrical main board where all the wires are mapped. I can get L + N for mysensors power supply. And i can continue to reuse the original wall switch independently of the Mysensors board.
Just to let you know that I solved the issue.
I found a library where you can control the speed and make sure it get to it's position.
You can find it here: https://github.com/netlabtoolkit/VarSpeedServo
I incorporated it in the Mysensor sketch and it works eventhoug it looks like it only goes like 90 degrees but it's enough for me :
#include <MySensor.h>
#include <SPI.h>
#include <VarSpeedServo.h>
// #include <Servo.h>
#define SERVO_DIGITAL_OUT_PIN 3
#define SERVO_MIN 0 // Fine tune your servos min. 0-180
#define SERVO_MAX 180 // Fine tune your servos max. 0-180
#define DETACH_DELAY 900 // Tune this to let your movement finish before detaching the servo
#define CHILD_ID 10 // Id of the sensor child
MySensor gw;
MyMessage msg(CHILD_ID, V_DIMMER);
VarSpeedServo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
// Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created Sensor gw(9,10);
unsigned long timeOfLastChange = 0;
bool attachedServo = false;
void setup()
{
// Attach method for incoming messages
gw.begin(incomingMessage);
// Send the sketch version information to the gateway and Controller
gw.sendSketchInfo("Servo", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID, S_COVER);
// Request last servo state at startup
gw.request(CHILD_ID, V_DIMMER);
}
void loop()
{
gw.process();
if (attachedServo && millis() - timeOfLastChange > DETACH_DELAY) {
myservo.detach();
attachedServo = false;
}
}
void incomingMessage(const MyMessage &message) {
myservo.attach(SERVO_DIGITAL_OUT_PIN);
attachedServo = true;
if (message.type==V_DIMMER) { // This could be M_ACK_VARIABLE or M_SET_VARIABLE
int val = message.getInt();
myservo.write(SERVO_MAX + (SERVO_MIN-SERVO_MAX)/100 * val,255,true); // sets the servo position 0-180
// Write some debug info
Serial.print("Servo changed. new state: ");
Serial.println(val);
} else if (message.type==V_UP) {
Serial.println("Servo UP command");
myservo.write(SERVO_MIN,255,true);
gw.send(msg.set(100));
} else if (message.type==V_DOWN) {
Serial.println("Servo DOWN command");
myservo.write(SERVO_MAX,255,true);
gw.send(msg.set(0));
} else if (message.type==V_STOP) {
Serial.println("Servo STOP command");
myservo.detach();
attachedServo = false;
}
timeOfLastChange = millis();
}
@GLAB No worries, was in a similar situation.. My perspective was on what the Node could be made to provide, not what could be done within Domoticz to address the requirement - eg Had heard of Dummy counters but had no experience nor understood their purpose, nor had ever used scripts.
I had been sending a logical ON/OFF as well as a cumulative total from the Node and hit the same hair-pulling scenario as yourself.
Now only the ON/OFF is sent and the short script makes the transposition within Domoticz to a dummy meter (I think kWhr) using the internal clock in Domoticz.
Have fun