//var valami = itemRegistry.getItem(‘Idojarasallomas_weewxoutTemp_C’).getState();
var values = [];
values.push(“user=…”);
values.push(“pass=…”);
var now = new Date();
values.push(“ev=” + now.getFullYear());
values.push(“ho=” + (now.getMonth() + 1));
values.push(“nap=” + now.getDate());
values.push(“ora=” + now.getHours());
values.push(“perc=” + now.getMinutes());
values.push(“mp=” + now.getSeconds());
values.push(“hom=16”); // C
values.push(“rh=45”); // %
values.push(“tipus=WS23XX”);
var valstr = values.join(“&”);
var server_url = “https://pro.idokep.hu/sendws.php”;
var url = server_url + “?” + valstr;
var response = actions.HTTP.sendHttpGetRequest(url);
This looks like Nashorn JavaScript, right? Also, pleas use code fences.
```
code goes here
```
So what happens on that line? Error in the log? What is the value of the Item? What is the type of the Item?
Log it.
If you are just getting started with OH 3, I strongly recommend installing the JS Scripting add-on which will provide ECMAScript 2022 which is almost a decade more recent than Nashorn. It also has an extensive helper library that comes with it that makes interacting with OH much easier.
I use application/javascript;version=ECMAScript-2021 What I found in the add ons
var valami = itemRegistry.getItem('Idojarasallomas_weewxoutTemp_C').getState();
In this line I would like to read out the current outside temperature from the Weather unit but I can not, I gess the syntax is not good. (I copy it from blockly)
I can only log through the console on the server ar it is possible through the home.openhab.org?
The itemRegistry isn’t mentioned anywhere because the helper library goes to great lengths to make sure you never have to struggle with weirdness in dealing with Java Objects and Classes (itemRegistry is a Java Class which returns a Java Item Object) in a JavaScript context. When you use the library as documented there you will pretty much always have a JavaScript Object.
In OH 3, Blockly converts to the older Nashorn JavaScript and it uses the raw interface to openHAB. No helpers. So you cannot look at the code generated by Blockly and use it in ECMAScript 2021 (technically you could but it takes a little bit of work) and you probably wouldn’t want to anyway. In OH 4 Blockly uses the newer JS so it is easier to look at the code it produces to learn.
So my recommendation is to either:
continue to use Blockly, in OH 4 it will be converted to the newer ECMAScript for you
use Nashorn JS for this rule so you can use the code generated by Blockly to learn from
abandon using Blockly to generate examples to learn from and review the add-on docs for how to do things.
Given the docs for the newer JS, that line should be:
var valami = items.Idojarasallomas_weewxoutTemp_C.state
Note that .state returns the state of the Item as a string. If you need to do math with it use .numericState and if you need to use units use .quantityState.
Always watch openhab.log when coding. You can see them in the console. If you’ve installed openHABian Frontail is running on port 9000 which can be accessed in the browser and follows openhab.log and events.log (in MainUI it will be an option under “other uis”, the little icon in the upper right corner. But I don’t think that it can be accessed through the openHAB Cloud service, only on the LAN.