How to get relay state?



  • repeater started, id 100
    send: 100-100-0-0 s=255,c=0,t=18,pt=0,l=5,st=ok:1.4.1
    send: 100-100-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    send: 100-100-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Relay
    send: 100-100-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 100-100-0-0 s=1,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    send: 100-100-0-0 s=2,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    send: 100-100-0-0 s=3,c=0,t=3,pt=0,l=5,st=ok:1.4.1

    I have 3 relays and i want to make a logic something like this; if 3.relay is on than 1. relay is off

    How can i get relay status in orginal sketch?

    "
    void incomingMessage(const MyMessage &message) {
    // We only expect one type of message from controller. But we better check anyway.
    if (message.type==V_LIGHT) {
    // Change relay state
    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
    // Store state in eeprom
    gw.saveState(message.sensor, message.getBool());
    // Write some debug info
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
    }
    "


  • Hero Member

    On http://www.mysensors.org/build/relay you will find apart from the Relay also a RelayWithButtonActuator Example.

    Do you have some kind of feedback from the relay indicating it's status? If so, connect that to the button input and done!



  • @daulagari Thank you. i am trying to learn "message.xxxxx" but it is hard for me.

    How can i get 1-2-3 variables from "message.xxxxx"? So i can find which relay get a command.

    send: 100-100-0-0 s=1,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    send: 100-100-0-0 s=2,c=0,t=3,pt=0,l=5,st=ok:1.4.1
    send: 100-100-0-0 s=3,c=0,t=3,pt=0,l=5,st=ok:1.4.1

    http://www.mysensors.org/build/sensor_api#the-full-api this link is very useful but very hard for me...

    +++ i have some trouble with your link ; http://forum.mysensors.org/topic/738/relaywithbuttonactuator-example-with-touch-sensor/7


  • Contest Winner

    @C.r.a.z.y.

    something like:

    if (message.sensor == CHILD_ID)
    {
      if (message.type == V_VAR2)
      //etc....


  • @BulldogLowell That's it! Thank you :+1:

    if (message.sensor==1 && message.getBool()==true)
    {....


Log in to reply
 

Looks like your connection to MySensors Forum was lost, please wait while we try to reconnect.