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

    Display text based on sensor value, is that possible?

    Scheduled Pinned Locked Moved Scripts
    dashboardcustom widgetscriptjavascripttemplate
    5 Posts 2 Posters 2.7k 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.
    • T Offline
      Tag MOD
      last edited by jkandasa

      Hi!,

      Using Mycontroller for over 1 year now and i have to say this is a rock solid piece of software!!.

      I was wondering if it is possible to display text on a dashboard based on a sensor value, i.e
      If my light sensor detects light, it might say on the dashboard "Warning hallway light is on", or when a door is open, "Garage door open.." Or "Garage door closed.."

      Another one would be If my heat storage is over 70 degrees, "Shower ready"

      I have tried to figure this one out, but i have no clue where to start...

      Hope someone can shine a light on this, thanks for thinking along and add features to mycontroller!

      Tag

      jkandasaJ 1 Reply Last reply Reply Quote 1
      • jkandasaJ Offline
        jkandasa @Tag
        last edited by

        @Tag We can achieve this by using script. I will come up with some script soon.

        1 Reply Last reply Reply Quote 0
        • T Offline
          Tag MOD
          last edited by

          Great thanks!!

          jkandasaJ 1 Reply Last reply Reply Quote 0
          • jkandasaJ Offline
            jkandasa @Tag
            last edited by jkandasa

            @Tag I have created simple template and script for this use case. You have to create this template and script on your MyController and add the following uid tags with mapping of your sensor variables.

            • hallway-light
            • garage-door
            • heat-storage
            HTML Template:
            <#list dispItems as index, item>
            <#if item.id??>
              <#switch item.type>
                <#case "SV">
                   <div class="mc-pointer" ui-sref="sensorsDetail({id: ${item.id} })">
                   <#break>
                <#case "S">
                   <div class="mc-pointer" ui-sref="sensorsDetail({id: ${item.id} })">
                   <#break>
                <#case "N">
                   <div class="mc-pointer" ui-sref="nodesDetail({id: ${item.id} })">
                   <#break>
                <#case "G">
                  <div class="mc-pointer" ui-sref="gatewaysDetail({id: ${item.id} })">
                <#break>
                <#default>
                  <div>
              </#switch>
            <#else>
              <div>
            </#if>
            
              <span><b><font color='${(item.color)!"black"}' size='${(item.size?c)!"2"}'>${(item.text)!"-"}</font></b></span></div>
            </#list>
            
            Java Script:
            var myImports = new JavaImporter(java.io, java.lang, java.util, java.text);
            
            with(myImports) {
              var hallwayLight = mcApi.uidTag().getByUid("hallway-light").getResource();
              var gatageDoor = mcApi.uidTag().getByUid("garage-door").getResource();
              var heatStorage = mcApi.uidTag().getByUid("heat-storage").getResource();
            
              var dispItems = [];
              //Check hallway light
              if(hallwayLight.value === '1'){
                dispItems.push({'text': "Warning hallway light is on", "color": "red", "size": 3, "type": "SV", "id": hallwayLight.sensor.id});
              }
            
              //Check garage door
              if(gatageDoor.value === '1'){
                dispItems.push({'text': "Garage door open.", "color": "red", "size": 3, "type": "SV", "id": gatageDoor.sensor.id});
              }else{
                dispItems.push({'text': "Garage door closed.", "color": "green", "size": 3, "type": "SV", "id": gatageDoor.sensor.id});
              }
            
              //Check shower
              if(parseFloat(heatStorage.value) >= 70.0){
                dispItems.push({'text': "Shower ready :) "+heatStorage.value+" °C", "color": "green", "size": 3, "type": "SV", "id": heatStorage.sensor.id});
              }else{
                dispItems.push({'text': "Heat storage temperature: "+heatStorage.value+" °C", "color": "orange", "size": 3, "type": "SV", "id": heatStorage.sensor.id});
              }
            }
            

            Here is the output. (Note: I have chnaged the script based on my requirement :))
            0_1487997011690_upload-fe551d40-f02f-426d-9088-f9082bf8db61

            Result:
            0_1487997048512_upload-89fb4e9e-e30f-4d5d-b6bb-b7c85f3b3459

            Note: All the text are clickable. If your hallway light is on and you want to turn it off, Just click on the text. It will take to to the sensors detail page. There you can control your hallway light. Have a fun 😉

            T 1 Reply Last reply Reply Quote 0
            • T Offline
              Tag MOD @jkandasa
              last edited by

              @jkandasa

              Just tested and it works like a charm!!!
              Really great examples, that are easy to implement.

              Mycontroller was already great, now it is even better!!.

              Thank you!!

              1 Reply Last reply Reply Quote 2
              • First post
                Last post

              0

              Online

              587

              Users

              529

              Topics

              3.4k

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