Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Get Relay State

Get Relay State

Scheduled Pinned Locked Moved Development
4 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikeones
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • epierreE Offline
      epierreE Offline
      epierre
      Hero Member
      wrote on last edited by
      #2

      you should write the last k own status in a var and request the var on startuo

      z-wave - Vera -> Domoticz
      rfx - Domoticz <- MyDomoAtHome <- Imperihome
      mysensors -> mysensors-gw -> Domoticz

      M 1 Reply Last reply
      0
      • epierreE epierre

        you should write the last k own status in a var and request the var on startuo

        M Offline
        M Offline
        mikeones
        wrote on last edited by mikeones
        #3

        @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);
        		}
        	}
        }
        
        1 Reply Last reply
        0
        • epierreE Offline
          epierreE Offline
          epierre
          Hero Member
          wrote on last edited by
          #4

          I don't know why you use a telay. Look at thr watermeter code, it uses the pattern I described above

          z-wave - Vera -> Domoticz
          rfx - Domoticz <- MyDomoAtHome <- Imperihome
          mysensors -> mysensors-gw -> Domoticz

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          38

          Online

          11.7k

          Users

          11.2k

          Topics

          113.1k

          Posts


          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • MySensors
          • OpenHardware.io
          • Categories
          • Recent
          • Tags
          • Popular