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
1 out of 4
Suggested Topics
-
Arduino Celebrates 10 years (Malmö/Sweden)
Announcements • 29 Mar 2014, 17:08 • hek 29 Mar 2014, 17:08 -
Gateway without a radio
Development • 12 Jan 2025, 23:19 • OldSurferDude 14 Jan 2025, 22:07 -
Saving last known good state, but not in EEPROM
Development • 30 Jan 2024, 18:46 • OldSurferDude 15 Jan 2025, 08:51 -
Adding Listen only device to my system.
Development • 26 Feb 2025, 00:39 • dpcons 26 Feb 2025, 06:26 -
LAN8720A - will mysensors work with this module
Development • 13 Nov 2024, 17:06 • Marcin 15 Nov 2024, 10:59 -
Home Assistant/MySensors quirks
Development • 18 days ago • OldSurferDude 18 days ago