Hi there,
I’ve successfully implemented my ducted air conditioning dry contact control with the Vera using Henk’s relay actuator sketch and opto-couplers to handle the switching.
Thanks again Henk for creating such an interesting project.
I’ve been testing the “Relay Actuator with a button” and from my testing the local push button updates the state of the switch in Vera but does not toggle the local relay output? I’ve successfully modified the code to toggle the local relay (I’m new to coding) and it’s working as per my requirement. I’m looking at a cheap alternative to a commercial ZWave relay module.
The only issue I can find with this modification is that there is no verification with Vera to ensure the gw.sendVariable was successfully received. If I unplug power to the RF24 radio module on the local sensor the relay toggles but the Vera does not receive the update and we have a sync issue between the Vera device state and the local relay.
I’ve read through the sensors.h and tried to use “message_s getMessage” to check for a response from the Vera but I just don’t understand the code to make it work.
Here is the loop section from the sketch which includes an extra digitalWrite(RELAY_PIN, state==1?0:1);
I’ve added a comment at the point where the verification step is needed.
I’d appreciate any help at all. I’ll upload this sketch once complete.
void loop()
{
if (gw.messageAvailable()) {
// got new messsage from gw
message_s message = gw.getMessage();
setRelayStatus(message);
}
buttVal = digitalRead(BUTTON_PIN); // read input value and store it in val
if (buttVal == HIGH && previousVal == LOW) {
// Start counter from when button was pressed
pressTime = millis();
switched = 0;
}
if (buttVal == HIGH && switched == 0 && millis() - pressTime > debounce) {
// Switch state if button pressed more than debounce msec
state = state==1?0:1;
// Debug the action of the switch
Serial.println("Button pressed");
gw.sendVariable(CHILD_ID, V_LIGHT, state); // We will receive an ack message
switched = 1; // No more switches until button is released
/* ##############################################################################
Insert a verification check with the Vera to ensure the message was received and the sensor state updated
so we can then change the state of the local relay.
##############################################################################
*/
}
// Added this line to change the state of the local relay
digitalWrite(RELAY_PIN, state==1?0:1);
}
previousVal = buttVal;
}