Announcement

Collapse
No announcement yet.

Post Messages from HomeSeer To a Telagram Group

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Post Messages from HomeSeer To a Telagram Group

    Is this possible?
    RJ_Make On YouTube

    #2
    Start here and read all about it : https://haefelfinger.ch/posts/2019/2...mqtt-telegram/ then : https://www.iotwithus.com/send-messa...-and-node-red/

    For integration with HomeSeer : https://shop.homeseer.com/products/mcsmqtt-software-plug-in-for-hs3 or https://shop.homeseer.com/products/mqtt-software-plug-in-for-hs3

    It is possible if you're willing to do the mileage.



    Eman.

    TinkerLand : Life's Choices,"No One Size Fits All"

    Comment


      #3
      There is an easier way, without MQTT. We use our Telegram bot in a group to get event messages immediately (doorbell, washer done, dryer done, car charged, smoke alarm, CO alarm, water leaks).

      - (Set up a Telegram account and the group).
      - Talk to BotFather and follow the steps to setup your bot (with the /newbot command, naming it, giving it a username and if wanted a description via /setdescription).
      - Invite your bot to the group.
      - During the process you've gotten your bot's token, which looks something like 123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ
      - In a browser go to https://api.telegram.org/bot<YourToken>/getUpdates (so in this example, https://api.telegram.org/bot12345678...xYZ/getUpdates) and lookup the chat ID for your bot with the group, which could look like -987654321
      - To send your message from an event, choose Run Another Program or Process, edit to /Windows/System32/curl.exe and set the parameters to "https://api.telegram.org/bot<YourToken>/sendMessage?chat_id=<YourChatID>&text=<YourText>" (so in this example, "https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text=Hello world!")
      (This used to be possible with the urlaction command, but stopped working about 2 months ago due to Telegram updating to TLS1.3).

      That's it.

      More info: https://core.telegram.org/bots/api

      Comment


        #4
        That worked perfectly Bernold Thank you. Does the parameters allow for device variables ($$DTR:3688 (strings)
        RJ_Make On YouTube

        Comment


          #5
          Not that way (works only for email and speech, I think). You can however use hs.DeviceValue(3688).

          To use this, rewrite the event to Run a Script or Script Command, Immediate script command (instead of Run Another Program or Process):
          - hs.launch("curl.exe","https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text=Device value="&hs.DeviceValue(3688),"/Windows/System32/",0)

          Comment


            #6
            Originally posted by Bernold View Post
            Not that way (works only for email and speech, I think). You can however use hs.DeviceValue(3688).

            To use this, rewrite the event to Run a Script or Script Command, Immediate script command (instead of Run Another Program or Process):
            - hs.launch("curl.exe","https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text=Device value="&hs.DeviceValue(3688),"/Windows/System32/",0)
            Thank you for all your help. It posts the word "Device" instead of the string.
            RJ_Make On YouTube

            Comment


              #7
              Originally posted by ServiceXp View Post

              Thank you for all your help. It posts the word "Device" instead of the string.
              Rather than an immediate script command, this may be better from a small script. In it you can use the device value properly.
              HS 3.0.0.548: 1990 Devices 1172 Events
              Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

              Comment


                #8
                Originally posted by ServiceXp View Post

                Thank you for all your help. It posts the word "Device" instead of the string.
                Sorry, I only tested with short texts. It helps to use %20 instead of spaces. That said, I agree that it's better to put it in a small script instead.
                Also, it's probably better to use hs.DeviceValueEx, otherwise decimal values are truncated.

                So, this should work:

                hs.launch("curl.exe","https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text=Device%20value="&hs.DeviceValueEx(3688),"/Windows/System32/",0)

                Edit:
                Just thought of another way. The key is to get the quotes parsed to curl.exe, which you can do with Chr(34):
                hs.launch("curl.exe",Chr(34)&"https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text=Device value = "&hs.DeviceValueEx(3688)&" (More spaced text here if wanted :-)"& Chr(34),"/Windows/System32/",0)

                Comment


                  #9
                  How would I create a script using it?

                  I tried this: But it generated a log Error (Below)


                  Code:
                  Sub SendTelagramNewMedia(Optional ByVal Parms As String = "")
                  
                       hs.WriteLog("Telagram", "(Telagrram.vb script) Sending New Media Notice" & Parms)
                  
                       hs.launch("curl.exe",Chr(34)&"https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text=Device value = "&hs.DeviceValueEx(3688)&"(TEST"& Chr(34),"/Windows/System32/",0)
                  
                  
                  End Sub

                  Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Telagram.vb: Syntax error.
                  Compiling script C:\Program Files (x86)\HomeSeer HS3\scripts\Telagram.vb: Namespace or type specified in the Imports 'System.Core' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases.

                  If I use the Immediate method. This is what is published.

                  "Device value = 0 (TEST"
                  RJ_Make On YouTube

                  Comment


                    #10
                    This is the device that contains the information that I want to publish.
                    Attached Files
                    RJ_Make On YouTube

                    Comment


                      #11
                      Ok so I have it correctly posting using the Immediate method. This is what it ended up looking like. (thank you so much @Bernold)

                      hs.launch("curl.exe",Chr(34)&"https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text="&hs.DeviceString(3688)&" THIS IS A TEST "& Chr(34),"/Windows/System32/",0)

                      HOWEVER..

                      I would like to take everyone's suggestion and make use of this as a script, but no matter what I try, I continue to get the same errors as above.

                      Any idea's on what I should be looking for?
                      RJ_Make On YouTube

                      Comment


                        #12
                        Originally posted by ServiceXp View Post
                        Ok so I have it correctly posting using the Immediate method. This is what it ended up looking like. (thank you so much @Bernold)

                        hs.launch("curl.exe",Chr(34)&"https://api.telegram.org/bot123456789:AbC1DeF2gHIJkLm34NOPqrsTuV5WxYZ/sendMessage?chat_id=-987654321&text="&hs.DeviceString(3688)&" THIS IS A TEST "& Chr(34),"/Windows/System32/",0)

                        HOWEVER..

                        I would like to take everyone's suggestion and make use of this as a script, but no matter what I try, I continue to get the same errors as above.

                        Any idea's on what I should be looking for?
                        No problem, I learned some new things myself Good to see you got the direct method working now. As for the script, I'm afraid I can't be of much help there. I would have to copy/paste it together from examples myself and I can't make sense of the error just yet. All I notice now is that it says Telagrram.vb instead of Telegram.vb - but that's just a string and should make no difference.

                        Comment


                          #13
                          Originally posted by ServiceXp View Post

                          I would like to take everyone's suggestion and make use of this as a script, but no matter what I try, I continue to get the same errors as above.

                          Any idea's on what I should be looking for?
                          How are you calling the script? A screenshot of your event's script action parameters would be useful. The other thing to think about (once you have it running) is that you may be able to use the HS url functions, rather than using curl.
                          HS 3.0.0.548: 1990 Devices 1172 Events
                          Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                          Comment


                            #14
                            Originally posted by sparkman View Post

                            How are you calling the script? A screenshot of your event's script action parameters would be useful. The other thing to think about (once you have it running) is that you may be able to use the HS url functions, rather than using curl.
                            I was using urlaction until 2 months ago when Telegram upgraded to TLS1.3

                            Comment


                              #15
                              Originally posted by Bernold View Post

                              I was using urlaction until 2 months ago when Telegram upgraded to TLS1.3
                              You can set vb.net scripts to use TLS1.3 by adding this line to the script:

                              Code:
                              System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls13
                              HS 3.0.0.548: 1990 Devices 1172 Events
                              Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                              Comment

                              Working...
                              X