openHAB 3.0 Milestone 2 discussion

Hi all

I’m trying to execute a python command in a DSL-Rule:

val results = executeCommandLine(Duration.ofSeconds(5), "/usr/bin/python2", "python /etc/openhab/scripts/qmotion.py 38020964")
logInfo("rules", results)

The command does work from command line without sudo, but not from rule. I only get “null” as output in Logfile:

2020-11-05 15:53:34.863 [INFO ] [org.openhab.core.model.script.rules ] - null

Did I miss something or is this an issue?

Thanks

Try putting it into a script & run the script. I believe OH does not have a shell when running commands.

But does work in OH2 :slight_smile:

What version? a Whitelist was introduced for that binding after 2.5.0 was released.

@michaeljoos Try:

val results = executeCommandLine(Duration.ofSeconds(5), "/usr/bin/python2", "/etc/openhab/scripts/qmotion.py", "38020964")
1 Like

Xtend, the language Rules DSL is based upon, allows you as a short cut to call getters (i.e. .getState()) by calling it like a parameter (i.e. .state). It’s one of the many places where the creators of Xtend are trying and failing (IMO) to make the language simpler. I doubt there is anything that can be done about it from openHAB’s side.

Anyway, the tl;dr is we don’t actually have both. .state is a short hand for calling .getState().

In the other rules languages I think that protected and private are not thoroughly respected so you can get at the .state data member directly. And there is nothing to prevent that so calling .state in those languages will always be possible. But .getState() is still required because the Item class is used elsewhere where private and protected are followed. That’s my understanding at least.

Make each argument to python be a separate argument to executeCommandLine.

executeCommandLine(Duration.ofSeconds(5), "/usr/bin/python2", "python", "/etc/openhab/scripts/qmotion.py", "38020964")

Also, you are calling python twice, once as "/user/bin/python2" and then again as "python" which is likely generating an error.

The whitelist doesn’t apply to executeCommandLine. There is a security issue to add it though but I think it’s a lower priority now that the ability to create Rules is more protected with auth.

2 Likes

Can someone from oh3 build section take a look at this problem?

Problem with MergeList /var/lib/apt/lists/openhab.jfrog.io_openhab_openhab-linuxpkg_dists_testing_main_binary-i386_Packages

Can’t call method “policy” on an undefined value at /usr/bin/apt-show-versions line 56.

Thanks

Today Im upgrade from M1 to M2 and have issues with mobile application.
Normal openHAB android application can’t connect anymore and in openhab log I get that entry:

[WARN ] [ore.io.rest.auth.internal.AuthFilter] - Unauthorized API request: Invalid Basic authentication credentials

Im install OpenHAB BETA(2.15.12-beta) android application but it also have problem. When I click to servers settings and try add password it crash and jump to sitemap page… So I can’t try it…
It crash with that error:

11-05 18:11:24.805 13392 13392 V AudioManager: querySoundEffectsEnabled... 
11-05 18:11:24.885 13392 13392 I BlockMonitor: dispatchingThrewException In MainThread 
11-05 18:11:24.885 13392 13392 D AndroidRuntime: Shutting down VM 
11-05 18:11:24.886 13392 13392 I QarthLog: [PatchStore] createDisableExceptionQarthFile 
11-05 18:11:24.886 13392 13392 I QarthLog: [PatchStore] create disable file for org.openhab.habdroid.beta uid is 10238 --------- beginning of crash 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: FATAL EXCEPTION: main 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: Process: org.openhab.habdroid.beta, PID: 13392 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: kotlin.UninitializedPropertyAccessException: lateinit property whitespaceBehavior has not been initialized 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at org.openhab.habdroid.ui.preference.CustomInputTypePreference$PrefFragment.afterTextChanged(CustomInputTypePreference.kt:130) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.TextView.sendAfterTextChanged(TextView.java:10634) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.TextView.setText(TextView.java:6335) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.TextView.setText(TextView.java:6154) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.EditText.setText(EditText.java:122) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.TextView.setText(TextView.java:6106) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.TextView.setTransformationMethod(TextView.java:2625) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.widget.TextView.setInputType(TextView.java:6581) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at org.openhab.habdroid.ui.preference.CustomInputTypePreference$PrefFragment.onBindDialogView(CustomInputTypePreference.kt:96) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.preference.PreferenceDialogFragmentCompat.onCreateDialog(PreferenceDialogFragmentCompat.java:148) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:419) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.Fragment.performGetLayoutInflater(Fragment.java:1485) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:320) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1368) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1446) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1509) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2181) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2004) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1959) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:888) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.os.Looper.loop(Looper.java:213) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:8178) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513) 
11-05 18:11:24.890 13392 13392 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

I’ve checked error again and there is also error:

Encountered a section with no Package: header

I’ve checked file

/var/lib/apt/lists/openhab.jfrog.io_openhab_openhab-linuxpkg_dists_testing_main_binary-i386_Packages

and I’ve found at the end (line 1695):

Filename: pool/main/2.5.10/openhab2-addons_2.5.10-1_all.deb
SHA1: 1c171649fd4eb803db7fa04a21ec3feb21fa414d
SHA256: f7a240a166295b336afead20cc0af32aaeb2f1b1de425d0910ded9453d363ce6
Size: 199086412

and IMHO this is the problem why we can’t perform proper update process.

I submitted https://github.com/openhab/openhab-core/pull/1799 which I confirmed solves the abovementioned problem.

2 Likes

I saw that and it’s excellent news! :smiley:

Hi,

I just upgraded my rPi 4 from OH 2.5.10 to OH 3.0.0 M2 using Openhabian v1.6-952(a7fb26b). The upgrade was successful and I was able to bring up the OH 3.0.0 Main View. However, every time I tried to add a Binding, I would get the following error in the Openhab logs:

2020-11-06 04:02:54.400 [ERROR] [t.core.internal.addons.AddonResource] - Exception while installing add-on: null

It happens with all the add-ons I’ve tried.

Any ideas or thoughts?

Thanks,
Randy

Did you upgrade to Java11 as well?

1 Like

I think there is still an issue with the rrd4j on the latest build (#2005).

So, cfr all the discussions before, the Item here below is definitely a Number without a QuantityType. So, why is the value returned by rrd4j through HistoricState containing a UoM, whereas the data returned through the REST interface does not contain a UoM, and this UoM is only defined in the label of the Item? Changing DecimalType to Number eliminates the error, but the result it totally wrong

.Items:

Number TechnicalFacilitiesElectricityActiveEnergy “Technical Facilities - Electricity - Active Energy [%.2f kWh]”

rrd4j :

{“name”:“TechnicalFacilitiesElectricityActiveEnergy”,“datapoints”:“1406”,“data”:[{“time”:1604563080000,“state”:“123945.0”},{“time”:1604563140000,“state”:“123945.0”},{“time”:1604563200000,“state”:“123945.0”},{“time”:1604563260000,“state”:“123945.0”},{“time”:1604563320000,“state”:“123945.0”},{“time”:1604563380000,“state”:“123945.0”},{“time”:1604563440000,“state”:“123945.0”},{“time”:1604563500000,“state”:“123945.0”},{“time”:1604563560000,“state”:“123945.0”},{“time”:1604563620000,“state”:“123945.0”},{“time”:1604563680000,“state”:“123945.0”},{“time”:1604563740000,“state”:“123945.0”},{“time”:1604563800000,“state”:“123945.0”},{“time”:1604563860000,“state”:“123945.0”},{“time”:1604563920000,“state”:“123945.0”},{“time”:1604563980000,“state”:“123945.0”},{“time”:1604564040000,“state”:“123945.0”},{“time”:1604564100000,“state”:“123945.0”},{“time”:1604564160000,“state”:“123945.0”},{“time”:1604564220000,“state”:“123946.0”},{“time”:1604564280000,“state”:“123946.0”},{“time”:1604564340000,“state”:“123946.0”},{“time”:1604564400000,“state”:“123946.0”},{“time”:1604564460000,“state”:“123946.0”},{“time”:1604564520000,“state”:“123946.0”},{“time”:1604564580000,“state”:“123946.0”},{“time”:1604564640000,“state”:“123946.0”},

.rules:

logInfo("org.openhab", "Calculate daily electric energy consumption : Current : " + TechnicalFacilitiesElectricityActiveEnergy.state)
logInfo("org.openhab", "Calculate daily electric energy consumption : Midnight : " + TechnicalFacilitiesElectricityActiveEnergy.historicState(now.minusHours(now.getHour()).minusMinutes(now.getMinute())).state)
var gToday = TechnicalFacilitiesElectricityActiveEnergy.state as DecimalType - TechnicalFacilitiesElectricityActiveEnergy.historicState(now.minusHours(now.getHour()).minusMinutes(now.getMinute())).state as DecimalType
logInfo("org.openhab", "Calculate daily electric energy consumption : Today : " + gToday) 

bundles:
184 │ Active │ 80 │ 3.0.0.202011032318 │ org.openhab.core.persistence
248 │ Active │ 80 │ 3.0.0.202011020022 │ org.openhab.persistence.rrd4j

Output:

2020-11-06 08:41:44.567 [INFO ] [org.openhab.core.model.script.org.openhab ] - Calculate daily electric energy consumption : Current : 124008.0
2020-11-06 08:41:44.569 [INFO ] [org.openhab.core.model.script.org.openhab ] - Calculate daily electric energy consumption : Midnight : 123998.0 kWh
2020-11-06 08:41:44.571 [ERROR] [utomation.module.script.internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘consumption-3’ failed: Could not cast 123998.0 kWh to org.openhab.core.library.types.DecimalType; line 30, column 84, length 108 in consumption

If I now change the one line to

var gToday = TechnicalFacilitiesElectricityActiveEnergy.state as Number - TechnicalFacilitiesElectricityActiveEnergy.historicState(now.minusHours(now.getHour()).minusMinutes(now.getMinute())).state as Number

then the output is

Calculate daily electric energy consumption : Today : -446389075992.0

People would you please stay on topic.
If you have issues that are not of potentially widespread interest or not located inside OH3M2 (or OH3M* at least), open a new thread - else this one becomes unreadable.
Thank you.

1 Like

@mstormi Pls define inside . For me everything that is touched by a commit between M1 and M2 is inside M2. Since there were commits related to rrd4j/persistence, I do log issues on those.

Sounds to me like an issue you should report.
Background - a plain Number type can hold a unit in its state. You can via rule postUpdate a Number Item with e.g. “22 km”. (But of course you don’t get any autoscaling or conversion features etc. of the real Quantity Types).

That part’s not a persistence issue. The historicState.state() is correct in being, umm, “UoM capable” just like item.state

Persistence does need to able to deal in some way with plain Number Items actually having units - either not record them at all, or record-and-retrieve as they are (that’s probably difficult if it changes as you go along)…

However - it should not be making stuff up and adding UoM to retrieved data that didn’t have it when persisted.

I wonder if at the moment you can get silly units from "my label [%s apples]'

Yes - upgraded to Java 11:

openjdk version "11.0.8" 2020-07-14 LTS
OpenJDK Runtime Environment Zulu11.41+75-CA (build 11.0.8+10-LTS)
OpenJDK Client VM Zulu11.41+75-CA (build 11.0.8+10-LTS, mixed mode)

Ok, i am out of ideas now, can just confirm that M2 is working here without any flaws.

Maybe try to install the offline addons package…?