Get Relay State
-
Is there an options to get the state of a relay? The API shows there is a light status option but it looks like it only sets the state.
V_LIGHT 2 Light status. 0=off 1=on
Here is the part of the relay sketch I am looking at.
void setRelayStatus(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_LIGHT) { int incomingRelayStatus = atoi(message.data); // Change relay state digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF); // Write some debug info Serial.print("Incoming change for relay on pin:"); Serial.print(message.header.childId); Serial.print(", New status: "); Serial.println(incomingRelayStatus); } }
Is there something similar to the lock status variable for a relay?
V_LOCK_STATUS 36 Set or get lock status. 1=Locked, 0=Unlocked
-
you should write the last k own status in a var and request the var on startuo
-
@epierre What would that look like? I was thinking of sending back the status on request. Something like this.
void setRelayStatus(message_s message) { if (message.header.messageType==M_SET_VARIABLE && message.header.type==V_LIGHT) { int incomingRelayStatus = atoi(message.data); if incomingRelayStatus == 2 { gw.sendVariable(message.header.childId, V_LIGHT, digitalRead(message.header.childId)); } else { // Change relay state digitalWrite(message.header.childId, incomingRelayStatus==1?RELAY_ON:RELAY_OFF); // Write some debug info Serial.print("Incoming change for relay on pin:"); Serial.print(message.header.childId); Serial.print(", New status: "); Serial.println(incomingRelayStatus); } } }
-
I don't know why you use a telay. Look at thr watermeter code, it uses the pattern I described above