Widget - Sensor custom buttons


  • ADMIN

    With the request https://github.com/mycontroller-org/mycontroller/issues/47 we have introduced an option to add custom buttons with custom payload on dashboard.

    We can use this widget for multiple purpose. Here I have showed how to use it as a TV remote control. For this you should have IR send sensor board in front of tv.

    Edit dashboard and select add widgets. Select Sensor custom buttons
    Now select your IR send type sensor variable.
    You have to give 3 types of input

    • Minimum height - each button minimum height in px
    • Minimum weight - each button minimum weight in px
    • JSON - is the buttons/payloads configuration

    To create json configuration error free way use http://www.jsoneditoronline.org/

    In configuration we can give name, payload, btnType.

    • name - (Mandatory) Name of the button. can be in the form of HTML also. HTML or icons(recommended: font awesome icons)
      are mandatory fields.
    • payload - (Mandatory) When we click the button what is the payload we have to send
    • btnType - (Optional) can be any one of value in the list [default, primary, success, info, warning, danger] when we leave this field field as blank, default will be selected. Each value gives different color

    Example json configuration as follows,

    [
      {
        "name": "<i class='fa fa-power-off'></i>",
        "payload": "P",
        "btnType": "danger"
      },
      {
        "name": "1",
        "payload": "1"
      },
      {
        "name": "2",
        "payload": "2"
      },
      {
        "name": "3",
        "payload": "3"
      },
      {
        "name": "4",
        "payload": "4"
      },
      {
        "name": "5",
        "payload": "5"
      },
      {
        "name": "6",
        "payload": "6"
      },
      {
        "name": "7",
        "payload": "7"
      },
      {
        "name": "8",
        "payload": "8"
      },
      {
        "name": "9",
        "payload": "9"
      },
      {
        "name": "0",
        "payload": "0"
      },
      {
        "name": "<i class='fa fa-play'></i>",
        "payload": "PL",
        "btnType":"success"
      },
      {
        "name": "<i class='fa fa-pause'></i>",
        "payload": "PA",
        "btnType":"warning"
      }
    ]
    

    Note: In this example I have added dummy payloads. Real payload of TV remote will be different(TV to TV payload will be different).

    Final result:

    image





  • It is posible to send multiple Payloads with one Button?
    I need a Button for Power On/Off all Lamps, all connected to one 433MHz Node!


  • ADMIN

    @Takero1978 I do not know how 433MHz works. Multiple payload is not possible with custom button.

    It is possible by creating group. Resources >> Groups >> Add Group after created new group select View details of the group from table. Now add any number of resources you want. You have to specify ON payload and OFF payload.

    I think we have to introduce new widget to add groups in dashboard.



  • Thanks! Woks 🙂

    Now we need a Group Button for dashboards 💃


  • ADMIN

    @Takero1978 said:

    Group Button for dashboard

    Please create a request on Github. I will add group button for dashboard.



  • Looks like I will have a minimum of 50 buttons!

    Is there any (easy) way to subdivide them within the same sensors window graphically (to allow naturally grouped controls to be more instinctively noticed)...

    Just starting to test today 🙂


  • ADMIN

    @skywatch In the current mode, you can specify only on sensor variable and different buttons with different payloads.

    You can change a style of the button, but you cannot subdivide them. You may need to create multiple widgets to achieve this approach.



  • It looks like this is sending a string to the node.

    If I want to send hex codes, would this be the most suitable way to do it and what should I add to the node to receive this?

    For example I could send 0xDB12DA34 as a string and be able to send as a hex code from the node?

    Would this work at the node to get the data?

     receive(const MyMessage &message){        
       if (message.type == V_IR_SEND)
       {
        String code = message.getString()
         irsend.sendNEC(code, 32);
       }
    

    Thanks



  • What I posted will not work, so here is the new code in full.....It compiles, but that doesn't mean it will do what I expect!

    My aim is to remove most of the hex code #define statements and have those hex values sent in the button payload of mysensors custom button JSON setup.
    This will save memory on the arduino.

    /*
       Based on IRsendDemo Copyright 2009 Ken Shirriff
       http://arcfn.com
    */
    #include <IRremote.h>
    /*
       Yamaha Amp DSP 592
       Function Code  Len
    */
    #define YTime/Level- 0x5EA1CA35
    #define YTime/Level+ 0x5EA14AB5
    #define YData/Centre 0x5EA1619E
    #define YTest 0x5EA1A15E
    #define YEffect 0x5EA16A95
    #define YProg- 0x5EA19A65
    #define YProg+ 0x5EA11AE5
    #define YProLogic 0x5EA111EE
    #define YEnhanced 0x5EA1916E
    #define YV-AUX 0x5EA1AA55
    #define YVCR 0x5EA1F00F
    #define YTV/DBS 0x5EA12AD5
    #define YDVD/LD 0x5EA1E817
    #define Y2CH/6CH 0x5EA1E11E
    #define YTAPE 0x5EA118E7
    #define YTUNER 0x5EA16897
    #define YCD 0x5EA1A857
    #define YPHONO 0x5EA128D7
    #define YSleep 0x5EA1EA15
    #define YPower 0x5EA1F807
    #define YVOL+ 0x5EA158A7
    #define YVOL- 0x5EA1D827
    /* 
       Optoma HD141X Projector
       Function Code  Len 
    */
    #define Power_ON 0x4CB340BF
    #define Power_OFF 0x4CB3748B
    #define USER1 0x4CB36C93
    #define USER2 0x4CB3A659
    #define USER3 0x4CB36699
    #define Brightness 0x4CB3827D
    #define Contrast 0x4CB342BD
    #define Mode 0x4CB3A05F
    #define Keystone 0x4CB3E01F
    #define Aspect 0x4CB326D9
    #define Optoma3D 0x4CB3916E
    #define Mute 0x4CB34AB5
    #define DB 0x4CB322DD
    #define OSleep 0x4CB3C639
    #define VOL+ 0x4CB38877
    #define VOL- 0x4CB328D7
    #define Source 0x4CB308F7
    #define Re-Sync 0x4CB348B7
    #define Enter 0x4CB3F00F
    #define Menu 0x4CB3708F
    #define HDMI1 0x4CB36897
    #define HDMI2 0x4CB30CF3
    //
    #define power_ON_macro 1111
    #define power_OFF_macro 2222
    #define CHILD_ID_FAN 0
    #define CHILD_ID_HEATER 1
    #define CHILD_ID_IR 2
    #define RELAY_ON 1
    #define RELAY_OFF 0
    #define Fan_ON 1
    #define Fan_OFF 0
    #define Heater_pin 4
    #define Fan_pin 5
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL   RF24_PA_LOW
    #define MY_NODE_ID 61
    #define MY_RF24_CHANNEL (97)
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    //#define MY_REPEATER_FEATURE
    //#define MY_SIGNING_ATSHA204
    //#define MY_SIGNING_REQUEST_SIGNATURES
    unsigned long last_heartbeat_time = 0;
    unsigned long HEARTBEAT_TIME = 5 * 60000;
    unsigned long value = 000000000;
    IRsend irsend;
    #include <Wire.h>
    #include <MySensors.h>
    MyMessage msgFan(CHILD_ID_FAN, V_STATUS);
    MyMessage msgHeater(CHILD_ID_HEATER, V_STATUS);
    MyMessage msgCode(CHILD_ID_IR, V_IR_SEND);
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("MYS-CinemaControl", "0.1");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_FAN, S_BINARY, "Cinema Fan");
      wait(100);
      present(CHILD_ID_HEATER, S_BINARY, "Cinema Heater");
      wait(100);
      present(CHILD_ID_IR, S_IR, "Cinema IR Send");
    }
    
    void setup()
    {
      pinMode(Fan_pin, OUTPUT); //pin 5
      digitalWrite(Fan_pin, LOW);
      pinMode(Heater_pin, OUTPUT); //pin4
      digitalWrite(Heater_pin, LOW);
    }
    
    void loop() {
      if ((millis() - last_heartbeat_time) > HEARTBEAT_TIME) {
        sendHeartbeat();
        last_heartbeat_time = millis();
      }
    }
    
    // process incoming message
    void receive(const MyMessage &message) {
      if (message.type == V_IR_SEND)
      {
        unsigned long  code = message.getString();
        value = strtoul(code, NULL, 16);  
        Serial.print("code = ");
        Serial.print(code);
        Serial.print(" Value = ");
        Serial.println(value);
      
      }
      if (value == power_OFF_macro)
      {
        irsend.sendNEC(YPower, 32);
        delay(500);
        irsend.sendNEC(Power_OFF, 32);
        delay(1000);
        irsend.sendNEC(Power_OFF, 32);
      }
      else if (value == power_ON_macro)
      {
        irsend.sendNEC(YPower, 32);
        delay(500);
        irsend.sendNEC(Power_ON, 32);
      }
        else{
        irsend.sendNEC(value, 32);
        }
    if (message.type == V_STATUS){
        digitalWrite(message.sensor+4, message.getBool()?RELAY_ON:RELAY_OFF);
        } 
    }
    

    I'll be testing later today I hope! 🙂



  • I have this working now, but how do I deal with buttons that repeat the code (volume)?


  • ADMIN

    @skywatch You have to release and click again and again. Also, handle the logic in your Arduino sketch.



  • @jkandasa I have thought about that, but it is sooo tedious without a servant to do it for one! - So I will try programming the arduino node to automatically repeat the signal on seeing the command for the first time, then, when volume is as you like it I can send second command that will stop the loop counting up or down. I guess the same would apply to lighting controls that require a button to be held down to dim or brighten lights via IR?


  • ADMIN

    @skywatch

    I guess the same would apply to lighting controls that require a button to be held down to dim or brighten lights via IR?

    This one may not be performed from the MyController side. Again this should be handled by Arduino sketch. I do not get any idea to implement this one with MyController



  • @jkandasa

    I do not get any idea to implement this one with MyController

    I have an idea - what about a option to select whether or not to 'repeat' the command on button push (tick box) and then with a variable to define how often the 'message' should be sent per second.

    This needs to be achieved with a way to detect a button push and button release.

    But not something to take your time away from more important things 😉


  • ADMIN

    @skywatch Kindly create a request on GitHub page, I will work on this when I get time.

    Thank you!



  • @jkandasa Thanks - But I am the only one with use for this and it is better for your time to be spent on new MyController instead! I can manage with it how it is for a long time 😉


  • ADMIN

    @skywatch Thank you! 🙂



  • Just an update to show that you guys are awesome.... Here is an image of the current setup...

    0_1533399149910_IR_Control_Screen.jpg

    And in case anyone else is stuck with this type of thing, here is the final fully working code.

    /*
       Based on IRsendDemo Copyright 2009 Ken Shirriff
       http://arcfn.com
    */
    #include <IRremote.h>
    /*
       Yamaha Amp DSP 592
       Function Code  Len
    */
    #define YPower 0x5EA1F807
    /*  
     Optoma HD141X Projector
       Function Code  Len 
    */
    #define Power_ON 0x4CB340BF
    #define Power_OFF 0x4CB3748B
    //
    #define power_ON_macro 0x11111111
    #define power_OFF_macro 0x22222222
    #define CHILD_ID_FAN 0
    #define CHILD_ID_HEATER 1
    #define CHILD_ID_IR 2
    #define RELAY_ON 0
    #define RELAY_OFF 1
    #define Fan_ON 0
    #define Fan_OFF 1
    #define Heater_pin 4
    #define Fan_pin 5
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    #define MY_RF24_PA_LEVEL   RF24_PA_LOW
    #define MY_NODE_ID 61
    #define MY_RF24_CHANNEL (97)
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    //#define MY_REPEATER_FEATURE
    //#define MY_SIGNING_ATSHA204
    //#define MY_SIGNING_REQUEST_SIGNATURES
    unsigned long last_heartbeat_time = 0;
    unsigned long HEARTBEAT_TIME = 5 * 60000;
    unsigned long code = 0x12345678;
    IRsend irsend;
    #include <Wire.h>
    #include <MySensors.h>
    MyMessage msgFan(CHILD_ID_FAN, V_STATUS);
    MyMessage msgHeater(CHILD_ID_HEATER, V_STATUS);
    MyMessage msgCode(CHILD_ID_IR, V_IR_SEND);
    
    void presentation()
    {
      // Send the sketch version information to the gateway
      sendSketchInfo("MYS-CinemaControl", "0.2");
    
      // Register all sensors to gw (they will be created as child devices)
      present(CHILD_ID_FAN, S_BINARY, "Cinema Fan");
      wait(100);
      present(CHILD_ID_HEATER, S_BINARY, "Cinema Heater");
      wait(100);
      present(CHILD_ID_IR, S_IR, "Cinema IR Send");
    }
    
    void setup()
    {
      pinMode(Fan_pin, OUTPUT); //pin 5
      digitalWrite(Fan_pin, HIGH);
      pinMode(Heater_pin, OUTPUT); //pin4
      digitalWrite(Heater_pin, HIGH);
    }
    
    void loop() {
      if ((millis() - last_heartbeat_time) > HEARTBEAT_TIME) {
        sendHeartbeat();
        last_heartbeat_time = millis();
      }
    } 
    
    // process incoming message
    void receive(const MyMessage &message) {
        if (message.type == V_IR_SEND){
        unsigned long code = strtoul(message.getString(),NULL,0);
      
      if (code == power_OFF_macro)
      {    
        irsend.sendNEC(Power_OFF, 32);
        delay(1500);
        irsend.sendNEC(YPower, 32);
        delay(1500);
        irsend.sendNEC(Power_OFF, 32);
      }
      if (code == Power_OFF)
      {
        irsend.sendNEC(Power_OFF, 32);
        delay(3000);
        irsend.sendNEC(Power_OFF, 32);
      }
      else if (code == power_ON_macro)
      {
        irsend.sendNEC(Power_ON, 32);
        delay(2000);
        irsend.sendNEC(YPower, 32);
      }
      else{
        irsend.sendNEC(code, 32);
       }
      }
        if (message.type == V_STATUS){
        digitalWrite(message.sensor+4, message.getBool()?RELAY_ON:RELAY_OFF);
      } 
    }
    

    I managed to get most of the ir code #define statements off the arduino and instead store them in the button code on the pi, which saves memory on the arduino for future expansion.

    And here is the JSON code for the buttons, the hex codes will need to be changed to whatever you need...

    [
     {
        "name": "Power ON Macro",
        "payload": "0x11111111",
        "btnType": "danger"
      },
     {
        "name": "Power OFF Macro",
        "payload": "0x22222222",
        "btnType": "danger"
      },
      {
        "name": "Amp Power",
        "payload": "0x5EA1F807"
      },
      {
        "name": "Amp Vol +",
        "payload": "0x5EA158A7"
      },
      {
        "name": "Amp Vol -",
        "payload": "0x5EA1D827"
      },
      {
        "name": "CD",
        "payload": "0x5EA1A857"
      },
      {
        "name": "Phono",
        "payload": "0x5EA128D7"
      },
      {
        "name": "Bluray",
        "payload": "0x5EA1E817"
      },
      {
        "name": "Amp Kodi",
        "payload": "0x5EA12AD5"
      },
     {
        "name": "Tape",
        "payload": "0x5EA118E7"
      },
     {
        "name": "Tuner",
        "payload": "0x5EA16897"
      },
     {
        "name": "V-Aux",
        "payload": "0x5EA1AA55"
      },
      {
        "name": "Time/Level +",
        "payload": "0x5EA14AB5"
      },
      {
        "name": "Time/Level -",
        "payload": "0x5EA14AB5"
      },
      {
        "name": "Effect",
        "payload": "0x5EA16A95"
      },
    {
    "name" : "2Ch/6Ch",
    "payload": "0x5EA1E11E"
    },
    {
    "name" : "Prog+",
    "payload": "0x5EA11AE5"
    },
    {
    "name" : "Prog -",
    "payload": "0x5EA19A65"
    },
    {
    "name" : "Enhanced",
    "payload": "0x5EA1916E"
    },
      {
        "name": "Data/Centre/Rear/Swfr",
        "payload": "0x5EA1619E"
      }
     
    ]
    

  • ADMIN

    @skywatch Awesome!! great sharing. Thank you so much!


 

Suggested Topics

12
Online

392
Users

365
Topics

2.2k
Posts