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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login