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. Controllers
  3. Home Assistant
  4. An HASS service to send messages to nodes

An HASS service to send messages to nodes

Scheduled Pinned Locked Moved Home Assistant
homeautomationhome assistanthome-assistant
22 Posts 4 Posters 6.0k Views 3 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.
  • X Offline
    X Offline
    xlcnd
    wrote on last edited by
    #4

    I already use node-to-node communication for other proposes, however that doesn't help if I want to use HA automation (and not only update the status of a sensor) ...

    martinhjelmareM 1 Reply Last reply
    0
    • korttomaK Offline
      korttomaK Offline
      korttoma
      Hero Member
      wrote on last edited by
      #5

      Ahh, now I understand. Your request was directed at "Home Assistant". I don't know anything about Home Assistant sorry.

      • Tomas
      1 Reply Last reply
      0
      • X xlcnd

        I already use node-to-node communication for other proposes, however that doesn't help if I want to use HA automation (and not only update the status of a sensor) ...

        martinhjelmareM Offline
        martinhjelmareM Offline
        martinhjelmare
        Plugin Developer
        wrote on last edited by
        #6

        @xlcnd

        Hi!

        Could you give a detailed example how you would use the service and what message to send using the mysensors protocol? Then I can start building a solution around that.

        1 Reply Last reply
        0
        • X Offline
          X Offline
          xlcnd
          wrote on last edited by
          #7

          Hi,

          Thanks for your promptly reply.

          I have a node that acts like a IR remote to one of the newest Samsung TVs. This node runs a sketch that extracts IR codes from received messages and send them to TV and returns a feedback message to HASS. The node (with id 40) has a child sensor (with id 3) and his of type S_IR and accepts messages with type V_IR_SEND. In HASS this (ms)sensor is defined as a sensor (his identity_id is sensor.ir_remote) and displays the IR code that was sent, but there is no way in HASS to send a given IR code (for instance in automation) to this node... so a service to do that would be nice.

          X 1 Reply Last reply
          1
          • X xlcnd

            Hi,

            Thanks for your promptly reply.

            I have a node that acts like a IR remote to one of the newest Samsung TVs. This node runs a sketch that extracts IR codes from received messages and send them to TV and returns a feedback message to HASS. The node (with id 40) has a child sensor (with id 3) and his of type S_IR and accepts messages with type V_IR_SEND. In HASS this (ms)sensor is defined as a sensor (his identity_id is sensor.ir_remote) and displays the IR code that was sent, but there is no way in HASS to send a given IR code (for instance in automation) to this node... so a service to do that would be nice.

            X Offline
            X Offline
            xlcnd
            wrote on last edited by
            #8

            @xlcnd

            By the way, for now I implemented some of more useful function by using several child sensors of the type S_LIGHT and with the help of 'boolean' logic I select the intended IR code. But this produces complex sketches and a fair amount of rules in automation... just to send a code!

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xlcnd
              wrote on last edited by
              #9

              In the next version of HASS there is a new component that will do this (acting as an IR remote), however doesn't use mysensors but LIRC and a Raspberry Pi...

              1 Reply Last reply
              0
              • martinhjelmareM Offline
                martinhjelmareM Offline
                martinhjelmare
                Plugin Developer
                wrote on last edited by martinhjelmare
                #10

                My current plan is to move the IR send type to HA switch platform, and add a custom service that takes an attribute for the code.

                I haven't really looked into the details if this will work but I think so. Some of the devs have had a discussion about if there should be a common "remote" component where different platforms, LIRC, mysensors, etc, can interface their devices, but no actual plan has been finished.

                Until a better option is realised, I think the switch platform will be OK.

                X 1 Reply Last reply
                0
                • martinhjelmareM martinhjelmare

                  My current plan is to move the IR send type to HA switch platform, and add a custom service that takes an attribute for the code.

                  I haven't really looked into the details if this will work but I think so. Some of the devs have had a discussion about if there should be a common "remote" component where different platforms, LIRC, mysensors, etc, can interface their devices, but no actual plan has been finished.

                  Until a better option is realised, I think the switch platform will be OK.

                  X Offline
                  X Offline
                  xlcnd
                  wrote on last edited by
                  #11

                  @martinhjelmare But would be possible to change that attribute in automation? E.g., could the same switch receive several codes?

                  If not, this will not be a major improvement relative to the present situation...

                  martinhjelmareM 1 Reply Last reply
                  0
                  • X xlcnd

                    @martinhjelmare But would be possible to change that attribute in automation? E.g., could the same switch receive several codes?

                    If not, this will not be a major improvement relative to the present situation...

                    martinhjelmareM Offline
                    martinhjelmareM Offline
                    martinhjelmare
                    Plugin Developer
                    wrote on last edited by
                    #12

                    @xlcnd

                    I imagine it should work similar to how you can set brightness for a light in automation etc. So yes, you should be able to use logic to set different codes. Although, as I said, I haven't looked into all details, so we'll see what will be possible.

                    One problem I foresee is that it should preferably work as a push button, but switches in HA usually work as flip switches. Ie they stay in the state you switch them into. But I guess we want the device to turn on, send a code and then turn back to off state.

                    X 1 Reply Last reply
                    0
                    • martinhjelmareM martinhjelmare

                      @xlcnd

                      I imagine it should work similar to how you can set brightness for a light in automation etc. So yes, you should be able to use logic to set different codes. Although, as I said, I haven't looked into all details, so we'll see what will be possible.

                      One problem I foresee is that it should preferably work as a push button, but switches in HA usually work as flip switches. Ie they stay in the state you switch them into. But I guess we want the device to turn on, send a code and then turn back to off state.

                      X Offline
                      X Offline
                      xlcnd
                      wrote on last edited by
                      #13

                      @martinhjelmare In that case it will be VERY useful.

                      I have been playing with HA and LIRC on a Raspberry Pi (that acts as a remote near one of the new Samsung TVs) and found that the ability to send an IR code from HA is only useful for 'direct functions' like POWER, MUTE, SOURCE, VOL UP and VOL DOWN. Due to security reasons the appliance manufacturer's are limiting these cases and relying on context codes, like using arrows to select the appropriate choice, this makes the remote a not very useful concept to use in automation! Fortunately, if HA sends a code that represents the final goal (e.g. goto BBC), instead of the IR code, it is relatively easy to guess the appropriated steps in the node and send a sequence of codes to the appliance. The logic for that is better to be in the node not in HA because, even if in HA you know the sequence of IR codes, playing directly these codes in the node, make the process very unreliable (a small delay in the transmission and you will end up on Fox News instead!).

                      So your solution, in fact, is BETTER than a generic remote.

                      However, I don't see advantages to move 'IR send' to a switch, let it stay as a sensor whose state is the 'last code sent' together with a service that sends messages to that sensor... anyway this is a thing that will be useful for automation not so much as a UI gadget

                      martinhjelmareM 1 Reply Last reply
                      0
                      • X xlcnd

                        @martinhjelmare In that case it will be VERY useful.

                        I have been playing with HA and LIRC on a Raspberry Pi (that acts as a remote near one of the new Samsung TVs) and found that the ability to send an IR code from HA is only useful for 'direct functions' like POWER, MUTE, SOURCE, VOL UP and VOL DOWN. Due to security reasons the appliance manufacturer's are limiting these cases and relying on context codes, like using arrows to select the appropriate choice, this makes the remote a not very useful concept to use in automation! Fortunately, if HA sends a code that represents the final goal (e.g. goto BBC), instead of the IR code, it is relatively easy to guess the appropriated steps in the node and send a sequence of codes to the appliance. The logic for that is better to be in the node not in HA because, even if in HA you know the sequence of IR codes, playing directly these codes in the node, make the process very unreliable (a small delay in the transmission and you will end up on Fox News instead!).

                        So your solution, in fact, is BETTER than a generic remote.

                        However, I don't see advantages to move 'IR send' to a switch, let it stay as a sensor whose state is the 'last code sent' together with a service that sends messages to that sensor... anyway this is a thing that will be useful for automation not so much as a UI gadget

                        martinhjelmareM Offline
                        martinhjelmareM Offline
                        martinhjelmare
                        Plugin Developer
                        wrote on last edited by
                        #14

                        @xlcnd

                        Sensors are read only so it doesn't make sense to have an actuator like an IR send device be a sensor. That said, I'll know more how all this will work out once I start planning the code in detail. The IR receive should still be a sensor.

                        X 1 Reply Last reply
                        0
                        • martinhjelmareM martinhjelmare

                          @xlcnd

                          Sensors are read only so it doesn't make sense to have an actuator like an IR send device be a sensor. That said, I'll know more how all this will work out once I start planning the code in detail. The IR receive should still be a sensor.

                          X Offline
                          X Offline
                          xlcnd
                          wrote on last edited by
                          #15

                          @martinhjelmare Yes, I know that a sensor is read only, but it is important that the state is available on HA, how will you do it with a switch?

                          martinhjelmareM 1 Reply Last reply
                          0
                          • X xlcnd

                            @martinhjelmare Yes, I know that a sensor is read only, but it is important that the state is available on HA, how will you do it with a switch?

                            martinhjelmareM Offline
                            martinhjelmareM Offline
                            martinhjelmare
                            Plugin Developer
                            wrote on last edited by
                            #16

                            @xlcnd

                            The IR code will be available as a state attribute. You will be able to check it in automations with a template and is_state_attr for example.

                            X 1 Reply Last reply
                            0
                            • martinhjelmareM martinhjelmare

                              @xlcnd

                              The IR code will be available as a state attribute. You will be able to check it in automations with a template and is_state_attr for example.

                              X Offline
                              X Offline
                              xlcnd
                              wrote on last edited by
                              #17

                              @martinhjelmare Great!

                              1 Reply Last reply
                              0
                              • martinhjelmareM Offline
                                martinhjelmareM Offline
                                martinhjelmare
                                Plugin Developer
                                wrote on last edited by
                                #18

                                PR here:
                                https://github.com/home-assistant/home-assistant/pull/2239

                                Example sketch used for testing:

                                /*
                                 * Documentation: http://www.mysensors.org
                                 * Support Forum: http://forum.mysensors.org
                                 *
                                 * http://www.mysensors.org/build/ir
                                 */
                                
                                #include <MySensor.h>
                                #include <SPI.h>
                                #include <IRLib.h>
                                
                                #define SN "IR Sensor"
                                #define SV "1.0"
                                #define CHILD_ID 1
                                
                                MySensor gw;
                                
                                char code[10] = "abcd01234";
                                char oldCode[10] = "abcd01234";
                                MyMessage msgCodeRec(CHILD_ID, V_IR_RECEIVE);
                                MyMessage msgCode(CHILD_ID, V_IR_SEND);
                                MyMessage msgSendCode(CHILD_ID, V_LIGHT);
                                
                                void setup()
                                {
                                  gw.begin(incomingMessage);
                                  gw.sendSketchInfo(SN, SV);
                                  gw.present(CHILD_ID, S_IR);
                                  // Send initial values.
                                  gw.send(msgCodeRec.set(code));
                                  gw.send(msgCode.set(code));
                                  gw.send(msgSendCode.set(0));
                                }
                                
                                void loop()
                                {
                                  gw.process();
                                  // IR receiver not implemented, just a dummy report of code when it changes
                                  if (String(code) != String(oldCode)) {
                                    Serial.print("Code received ");
                                    Serial.println(code);
                                    gw.send(msgCodeRec.set(code));
                                    strcpy(oldCode, code);
                                  }
                                }
                                
                                void incomingMessage(const MyMessage &message) {
                                  if (message.type==V_LIGHT) {
                                    // IR sender not implemented, just a dummy print.
                                    if (message.getBool()) {
                                      Serial.print("Sending code ");
                                      Serial.println(code);
                                    }
                                    gw.send(msgSendCode.set(message.getBool() ? 1 : 0));
                                    // Always turn off device
                                    gw.wait(100);
                                    gw.send(msgSendCode.set(0));
                                  }
                                  if (message.type == V_IR_SEND) {
                                    // Retrieve the IR code value from the incoming message.
                                    String codestring = message.getString();
                                    codestring.toCharArray(code, sizeof(code));
                                    Serial.print("Changing code to ");
                                    Serial.println(code);
                                    gw.send(msgCode.set(code));
                                  }
                                }
                                
                                1 Reply Last reply
                                0
                                • X Offline
                                  X Offline
                                  xlcnd
                                  wrote on last edited by
                                  #19

                                  Thanks!

                                  I am traveling but as soon as I get home I will test it.

                                  1 Reply Last reply
                                  0
                                  • X Offline
                                    X Offline
                                    xlcnd
                                    wrote on last edited by
                                    #20

                                    It works like a charm in version 0.22.1.

                                    For complex sequences of IR codes, I just send a 'fake' code and then the node selects the appropriate sequence.

                                    Thanks again!

                                    martinhjelmareM 1 Reply Last reply
                                    0
                                    • X xlcnd

                                      It works like a charm in version 0.22.1.

                                      For complex sequences of IR codes, I just send a 'fake' code and then the node selects the appropriate sequence.

                                      Thanks again!

                                      martinhjelmareM Offline
                                      martinhjelmareM Offline
                                      martinhjelmare
                                      Plugin Developer
                                      wrote on last edited by
                                      #21

                                      @xlcnd

                                      Thanks for the feedback and live testing!

                                      1 Reply Last reply
                                      0
                                      • X Offline
                                        X Offline
                                        xlcnd
                                        wrote on last edited by
                                        #22

                                        Let me complete the example given for the node when you use V_IR_SEND.

                                        In order to send IR codes you need to transform the
                                        code in an unsigned long:

                                            char ircode[11] = {0};  // in case your code takes the form of 0xE0E0FF0F
                                            ...
                                            if (message.type == V_IR_SEND) {
                                              String hexstring = message.getString();
                                              hexstring.toCharArray(ircode, sizeof(ircode));
                                              ...
                                              // get the code as an unsigned long
                                              unsigned long code = strtoul(ircode, NULL, 0);
                                        
                                              // with IRLib send the code to TV
                                              sendSAMSUNG(code);
                                              ...
                                        

                                        Very simple, ** but is hard to find an example**!

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


                                        15

                                        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