Display text based on sensor value, is that possible?
-
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
-
@Tag We can achieve this by using script. I will come up with some script soon.
-
Great thanks!!
-
@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 :))
Result:
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
-
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!!