How to use custome widget
-
Re: How to show several sensor readings in a single widget
Thanks @jkandasa for your help. I had to let this project rest for some time, but returned now.
I tried again without luck, so I decided to reduce the code to the bare minimum.
I defined the UID:
The Script file:
var myImports = new JavaImporter(java.io, java.lang, java.util, java.text); with(myImports) { var temperature = mcApi.uidTag().getByUid("Temp").getResource(); }
and HTML file:
<div>Outside temperature: °C</div>
But I still get the error when testing the html with script:
Realy don't know how to solve this (and been thinking about it for half a year)...
-
-
Hi @jkandasa,
of course the html file code was a copy/paste mistake, it looked as you said.
Upgrading to the latest snapshot did the trick, it's working now. Thank you very much (in this specific fact and for your amazing controller)
One last thing: is there a way to read sensor information without defining a UID for it? I plan to build 5-10 identical nodes sending about 10-15 values each. Defining UIDs for each of them would be some work, maybe I can also adress them using kind of gateway>node>sensor terminology. -
One last thing: is there a way to read sensor information without defining a UID for it? I plan to build 5-10 identical nodes sending about 10-15 values each. Defining UIDs for each of them would be some work, maybe I can also adress them using kind of gateway>node>sensor terminology.
Yes, it is possible. Have a look this blog: http://forum.mycontroller.org/topic/28/introduction
^ Here you can see how we used to query node data. the same way we have to use for sensors too. Inside each sensor list of sensor variables will be.var sensors = mcApi.sensor().getAll(options);
Some of options to filter:
nodeName
,nodeEui
,id
,sensorId
,name
,type
-
Well I tried, but did not get any useful output. Could you please give me an example code for reading node 1 sensor 1 and 2 and node 2 sensor 1 and 2? Do I have to cascade
.getAll(node).getAll(sensor)
? -
@Anduril No, cascade won't work. Let me find out a way for this.
-
Hey @jkandasa
I got a working system thanks to your help. Only one thing that doen't work as I like at the moment: Is it possible to write values to an imported variable?
I have a MySensors value (a number) that has an uidTag and can be read by js file. But how can I change the sensor and have it send to the node?
When I show the sensor in a sensor widget I can change it and it will update at the node.
A side question: is it normal/intended to deactivate focus on these sensor fields every few seconds (update: seems to be the update widget time
)? When I click on the value to change it I have few seconds until it will get inactive and the old value. If I hit enter before that 'timeout' it will update correctly.code:
var myImports = new JavaImporter(java.io, java.lang, java.util, java.text); with(myImports) { var ID = mcApi.uidTag().getByUid("node-ID").getResource(); } ID.value = 123;
-
A side question: is it normal/intended to deactivate focus on these sensor fields every few seconds (update: seems to be the update widget time)? When I click on the value to change it I have few seconds until it will get inactive and the old value. If I hit enter before that 'timeout' it will update correctly.
I understand that you are asking the question on dashboard widget(sensors). Yes, as per current design value will be updated every X seconds once. It is not a real-time.
To send/update payload you can use,
mcApi.sensor().sendPayload(ID);
Refer this link for more details: https://forum.mycontroller.org/topic/146/how-to-set-sensor-value-with-javascript/5
-
Thank you. Is it also possible to create buttons on custom widget? This way I could trigger the sendPayload only when needed and not always when refreshing the widget...
-
@anduril There is no direct options available. Let me have a look and update you