• Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login
  • Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login

TV Status or generic devices with ip address as gateway

Scheduled Pinned Locked Moved Developers Zone
scriptjavascriptping
5 Posts 2 Posters 2.5k Views 1 Watching
Loading More Posts
  • 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.
  • F Offline
    Fraid
    last edited by jkandasa 13 Apr 2017, 04:13

    Hi @jkandasa ,

    I'd like to be able to know when my TV is on. Thank to my friend, give me the idea to ping the chromecast. It's little hard to do with MySensor using gateway, because of space and old library. So I'd like to do it on MyController side.

    So, can we create a new Network type "Devices" with only IP address as property. And I'll be able to say turn off TV on no motion, and if TV is already off do nothing ?

    Or is their other way to handle than?

    J 1 Reply Last reply 13 Apr 2017, 17:51 Reply Quote 0
    • J Offline
      jkandasa @Fraid
      last edited by jkandasa 13 Apr 2017, 17:51

      @Fraid We can meet this requirement by using the script with the following steps,

      • Create a dummy status sensor variable for your TV(for ping status).
      • Create a UID tag for your dummy sensor variable.
      • Create a script to ping for your tv IP and update status. This script will update your dummy sensor as ON or OFF based on ping status.
      • Execute the script every x seconds/minutes once. based on your requirement. You can do other operations based on this dummy sensor variable.

      Dummy sensor

      0_1492105636790_upload-5e4a7202-bc4f-4451-90b5-641e81111ea7

      UID Tag

      0_1492105574757_upload-2ec84cee-5662-4c9a-9a32-553f5dd697bf

      Script

      var myImports = new JavaImporter(java.io, java.lang, java.util, java.text, java.net.InetAddress);
      
      with(myImports) {
        //Get sensor variable
        var statusVar =  mcApi.uidTag().getByUid(senVarUid).getResource();
        //Create pong object and update default values
        var pong = {};
        pong.reachable = false;
        pong.message = "";
        try{
          //Check reachable status
          var addresses = InetAddress.getAllByName(ip);
          for (var index = 0; index < addresses.length; index++) {
              if (addresses[index].isReachable(20000)) {
                  pong.reachable = true;
                  pong.message += "Reachable:["+ addresses[index]+"], ";
              } else {
                  pong.message += "Failed:["+ addresses[index]+"], ";
              }
          }
          
        }catch(ex){
          //If there is an exception, mark it not reachable and record exception message
          pong.reachable = false;
          pong.error = ex.message;
        }
        var pingable = pong.reachable == true ? "1" : "0";
        //Check previous value. Update if there is a change
        if(statusVar.value !== pingable){
          statusVar.value = pingable;
          //Send value to sensor
          mcApi.sensor().sendPayload(statusVar);
        }
      }
      

      When execute this script you have to pass following bindings,

      • pi and senVarUid
      • Example: {"ip":"localhost", "senVarUid":"tv-ping"}

      Hope this will address your requirement.

      1 Reply Last reply Reply Quote 0
      • F Offline
        Fraid
        last edited by 14 Apr 2017, 03:58

        @jkandasa Thank you it's perfectly working 😄 😄 😄 !
        I even dimmed the light when TV is turned on, awesome!

        Just to make sure I added a timer like following:
        *** Simple, Repeat[Interval:20 Seconds, Count:999999999], Executed count:75***
        If I set 0 he doesn't execute, so how can set infinite count ?

        J 1 Reply Last reply 14 Apr 2017, 11:56 Reply Quote 0
        • J Offline
          jkandasa @Fraid
          last edited by 14 Apr 2017, 11:56

          @Fraid

          Just to make sure I added a timer like following:
          *** Simple, Repeat[Interval:20 Seconds, Count:999999999], Executed count:75***
          If I set 0 he doesn't execute, so how can set infinite count ?

          I request you to set timer interval at least 30 seconds. We have ping time-out as 20 seconds(20000) in the script. It is better to go higher this value.
          Set -1 as count to run infinitely.

          1 Reply Last reply Reply Quote 0
          • F Offline
            Fraid
            last edited by 15 Apr 2017, 03:48

            @jkandasa thank you so much, it's working.

            1 Reply Last reply Reply Quote 0
            5 out of 5
            • First post
              5/5
              Last post

            0

            Online

            587

            Users

            529

            Topics

            3.4k

            Posts
            Copyright © 2015-2025 MyController.org | Contributors | Localization