Temperature rule doesn't work anymore since upgrade to 4.X

Hi,
i hope you maybe can help me cause i really have no clue what i should try anymore.

I have a small rule which worked fine since OH3 and probably broke since the 4.0, 4.1 or 4.2 upgrade. Here is the rule (i also added already some debug statements):

rule "ServerSchrank Luefter"
when
  Item server_temperatur changed
then
  logInfo("Server_Luefter", "Rule running!")
  if (server_temperatur.state > 30) {
    sendCommand(server_luefter, ON)
    logInfo("Server_Lufter", "Over30")
  }
  else if (server_temperatur.state < 28) {
    sendCommand(server_luefter, OFF)
    logInfo("Server_luefter", "less28")
  }
  else {
    logInfo("Server_Luefter", "foooo")
  }
end

The problem is, the rule now newer gets in the if or else if part… it always falls directly to else:

2024-08-18 22:31:26.377 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'server_temperatur' changed from 29.1 °C to 30.2 °C

2024-08-18 22:31:26.378 [INFO ] [hab.core.model.script.Server_Luefter] - Rule running!
2024-08-18 22:31:26.381 [INFO ] [hab.core.model.script.Server_Luefter] - foooo

Here is also the Item, incase its of interest:

//server stuff
Number:Temperature server_temperatur "Serverschrank_Oben Temperatur [%.1f °C]" <temperature> {channel="homematic:HmIP-STHD:NEQ1531613:000E9569A23B93:1#ACTUAL_TEMPERATURE"}

I only have the guess that it probly has todo with the UoM breaking changes. If fixed other rules regarding this change, they run fine now, but not this one… the rule isn’t used much, i only found out recently that its not working anymore.

1 Like

you have to compare e.g. against 30 [ā„ƒ] or use .numericState

i did try numericState already (found it i the forum here). i got this error using it:

 Script execution of rule with UID 'hallway-6' failed: 'numericState' is not a member of 'org.openhab.core.library.items.NumberItem

gonna try that 30 [ā„ƒ] now. Thanks!

mhh this:

if (server_temperatur.state > 30 [°C]) {

gets me this:

Configuration model 'hallway.rules' has errors, therefore ignoring it: [46,33]: no viable alternative at input '°C'

i also tried this way:

if (server_temperatur.state > "30 °C") {

and this gets me this:

2024-08-18 23:29:25.908 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'hallway-6' failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.lib.NumberExtensions.operator_greaterThan(org.openhab.core.types.Type,java.lang.Number) on instance: null in hallway

sorry, didn’t look closely: You’re (still :wink:) using DSL. There it’s 30|°C

1 Like

Ahhh thanks it works now!!! so via | i can define the Unit i guess?
yeah i ā€˜still’ use dsl… its easy two write. Well i do write some python scripts from time to time, but i’m not to deep into programming stuff and ECMA looks to much like Java :laughing:

that are the perfect requirements to go for blockly: all the fun and all the power without nasty searching for syntax errors. Have a try!

but i can’t save that in git… and stuff like blocky really tooo abstract for me xD
maybe i really should take a look at ECMA. Thanks again!!

why? it’s just JavaScript! The code tab shows everything

Just to elaborate, all managed configs, including Blockly rules, are plain text JSON stored in $OH_USERDATA/jsondb. The actual graphical part of the Blocks are stores as XML and can be mostly ignored, but the code generated is JS Scripting (ECMAScript with the openhab-js helper library) and it’s saved as part of the rule too.

For example, here’s a blockly script I use as a scratchpad as it appears in the JSONDB. First the rendered version:

  "blockly": {
    "class": "org.openhab.core.automation.dto.RuleDTO",
    "value": {
      "triggers": [],
      "conditions": [],
      "actions": [
        {
          "inputs": {},
          "id": "script",
          "configuration": {
            "blockSource": "\u003cxml xmlns\u003d\"https://developers.google.com/blockly/xml\"\u003e\u003cvariables\u003e\u003cvariable id\u003d\",O||,J~nM[UNg(oQbV4b\"\u003estartTime\u003c/variable\u003e\u003cvariable id\u003d\"5og#OaN@WO?C,w(Wh@oH\"\u003eendTime\u003c/variable\u003e\u003cvariable id\u003d\"sth,uAlh1Xm/@gDGdxKS\"\u003epacket_NUM\u003c/variable\u003e\u003cvariable id\u003d\"Xm2sw^F$?X/uE,]2lRWe\"\u003eLogLevel\u003c/variable\u003e\u003c/variables\u003e\u003cblock type\u003d\"variables_set\" id\u003d\"6Xc[5B8~kwfE:y%I3jfQ\" x\u003d\"107\" y\u003d\"417\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\",O||,J~nM[UNg(oQbV4b\"\u003estartTime\u003c/field\u003e\u003cvalue name\u003d\"VALUE\"\u003e\u003cblock type\u003d\"oh_zdt_amend\" id\u003d\"k#NsI5(l(CbBfOX+R}np\"\u003e\u003cmutation items\u003d\"4\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"operation\"\u003ewith\u003c/field\u003e\u003cvalue name\u003d\"baseZdt\"\u003e\u003cshadow type\u003d\"oh_zdt\" id\u003d\"vPipXq~)W37(h/W}VFT\u003d\"\u003e\u003cfield name\u003d\"day\"\u003e2024-07-21\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"oh_zdt_now\" id\u003d\"wu}p)jGUTud,Z9|(9*zj\"\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD0\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"qZOWPr19e{Bq_aK28cFr\"\u003e\u003cmutation blockType\u003d\"3\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e18\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD1\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"8drc]IlreJmX?fNo4^QK\"\u003e\u003cmutation blockType\u003d\"4\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e0\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD2\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"l7K;nB\u003dse7IlHP*BkcwL\"\u003e\u003cmutation blockType\u003d\"5\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e0\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD3\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"|HWAJJK0DfZ92]F)(o?O\"\u003e\u003cmutation blockType\u003d\"7\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e0\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cnext\u003e\u003cblock type\u003d\"variables_set\" id\u003d\"+`J8aR0QWdeX^JBf,}HT\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\"5og#OaN@WO?C,w(Wh@oH\"\u003eendTime\u003c/field\u003e\u003cvalue name\u003d\"VALUE\"\u003e\u003cblock type\u003d\"oh_zdt_amend\" id\u003d\"+W43j)WMM3YPj,.:-Yz1\"\u003e\u003cmutation items\u003d\"4\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"operation\"\u003ewith\u003c/field\u003e\u003cvalue name\u003d\"baseZdt\"\u003e\u003cshadow type\u003d\"oh_zdt\" id\u003d\"vPipXq~)W37(h/W}VFT\u003d\"\u003e\u003cfield name\u003d\"day\"\u003e2024-07-21\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"oh_zdt_now\" id\u003d\"bbD`TNg@HcHPRDJ)am[L\"\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD0\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"~@UVbiD;6`v4Dpgnd\u003dwy\"\u003e\u003cmutation blockType\u003d\"3\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e9\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD1\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"1;!O}d48wB~xeTMnhEFn\"\u003e\u003cmutation blockType\u003d\"4\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e0\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD2\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"Cr]SlcD.kS]beH3`7R;P\"\u003e\u003cmutation blockType\u003d\"5\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e0\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"ADD3\"\u003e\u003cblock type\u003d\"oh_zdt_temporal_unit\" id\u003d\"J!f?m~Q9*SB8*|$?\u003dA#/\"\u003e\u003cmutation blockType\u003d\"7\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"value\"\u003e0\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cnext\u003e\u003cblock type\u003d\"controls_if\" id\u003d\"m/opAwVS5hB_|QAC7pJ1\"\u003e\u003cvalue name\u003d\"IF0\"\u003e\u003cblock type\u003d\"logic_operation\" id\u003d\"K{cpf@6stVGvES}+#9$_\"\u003e\u003cfield name\u003d\"OP\"\u003eAND\u003c/field\u003e\u003cvalue name\u003d\"A\"\u003e\u003cblock type\u003d\"logic_compare\" id\u003d\"9RO9p1gl3[0_+]tdiAss\"\u003e\u003cfield name\u003d\"OP\"\u003eEQ\u003c/field\u003e\u003cvalue name\u003d\"A\"\u003e\u003cblock type\u003d\"variables_get\" id\u003d\"[*^7wu~g)|nBpJd0wxJC\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\"sth,uAlh1Xm/@gDGdxKS\"\u003epacket_NUM\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"B\"\u003e\u003cblock type\u003d\"math_number\" id\u003d\"UVXK]B@VL!-B340)v0KD\"\u003e\u003cfield name\u003d\"NUM\"\u003e2022600\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"B\"\u003e\u003cblock type\u003d\"oh_zdt_between\" id\u003d\".9qAUmP!hkpnbBN;mg]F\"\u003e\u003cfield name\u003d\"dateComparison\"\u003etime\u003c/field\u003e\u003cvalue name\u003d\"zdtOne\"\u003e\u003cshadow type\u003d\"oh_zdt\" id\u003d\"T1))Mc.@S]2f$ze{n\u003dqo\"\u003e\u003cfield name\u003d\"day\"\u003e2024-07-21\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"oh_zdt_now\" id\u003d\"JG6V/4%#1!1^hF4Vj|Ew\"\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"zdtTwo\"\u003e\u003cshadow type\u003d\"oh_zdt\" id\u003d\"ni3F3(|%yTrNr{D--[v6\"\u003e\u003cfield name\u003d\"day\"\u003e2024-07-21\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"variables_get\" id\u003d\"D04FzE*{Z_tzlGHYObXa\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\",O||,J~nM[UNg(oQbV4b\"\u003estartTime\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"zdtThree\"\u003e\u003cshadow type\u003d\"oh_zdt\" id\u003d\"9aNj~Ii5PdsJ-S|9?PP+\"\u003e\u003cfield name\u003d\"day\"\u003e2024-07-21\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"variables_get\" id\u003d\"ixm%LFd~oe`$I,rW82*}\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\"5og#OaN@WO?C,w(Wh@oH\"\u003eendTime\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cstatement name\u003d\"DO0\"\u003e\u003cblock type\u003d\"controls_if\" id\u003d\"z70:,$8jzZ*+b:WINN$,\"\u003e\u003cmutation else\u003d\"1\"\u003e\u003c/mutation\u003e\u003cvalue name\u003d\"IF0\"\u003e\u003cblock type\u003d\"logic_compare\" id\u003d\"ycI;0B5p2-)[b8mx4eCR\"\u003e\u003cfield name\u003d\"OP\"\u003eEQ\u003c/field\u003e\u003cvalue name\u003d\"A\"\u003e\u003cblock type\u003d\"oh_getitem_state\" id\u003d\"Qz(\u003dU~Wk\u003dpD)gR14KfTH\"\u003e\u003cvalue name\u003d\"itemName\"\u003e\u003cshadow type\u003d\"oh_item\" id\u003d\"acWt?nJ,I@eQMfX0soEv\"\u003e\u003cmutation itemName\u003d\"MyItem\" itemLabel\u003d\"MyItem\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"itemName\"\u003eMyItem\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"B\"\u003e\u003cblock type\u003d\"text\" id\u003d\"SibO[sIydn\u003d/15a6cv@p\"\u003e\u003cfield name\u003d\"TEXT\"\u003eON\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cstatement name\u003d\"DO0\"\u003e\u003cblock type\u003d\"oh_event\" id\u003d\"]*Eo9F7qx6}nEqS|ot,)\"\u003e\u003cfield name\u003d\"eventType\"\u003esendCommand\u003c/field\u003e\u003cvalue name\u003d\"value\"\u003e\u003cshadow type\u003d\"text\" id\u003d\"|Y//qY?rP0+go_f8)~%J\"\u003e\u003cfield name\u003d\"TEXT\"\u003evalue\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"text\" id\u003d\"|AL.v;gfpwqVnHNurD4G\"\u003e\u003cfield name\u003d\"TEXT\"\u003eOFF\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"itemName\"\u003e\u003cshadow type\u003d\"oh_item\" id\u003d\"/G8NF#;?75fl\u003dkR@MAe[\"\u003e\u003cmutation itemName\u003d\"MyItem\" itemLabel\u003d\"MyItem\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"itemName\"\u003eMyItem\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003cnext\u003e\u003cblock type\u003d\"controls_if\" id\u003d\".M17|4x0wbG+{~Vg}meu\"\u003e\u003cvalue name\u003d\"IF0\"\u003e\u003cblock type\u003d\"logic_compare\" id\u003d\"6ui+aIKNG7@\u003dSD]Y@3w(\"\u003e\u003cfield name\u003d\"OP\"\u003eEQ\u003c/field\u003e\u003cvalue name\u003d\"A\"\u003e\u003cblock type\u003d\"variables_get\" id\u003d\"[d:ubxAYjwI*8-O,3,{1\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\"Xm2sw^F$?X/uE,]2lRWe\"\u003eLogLevel\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"B\"\u003e\u003cblock type\u003d\"math_number\" id\u003d\"NJnd/#Ob\u003dgVEP~Yynj;i\"\u003e\u003cfield name\u003d\"NUM\"\u003e1\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cstatement name\u003d\"DO0\"\u003e\u003cblock type\u003d\"oh_say\" id\u003d\"g:U4N%DN]C_3){ARbB)2\"\u003e\u003cvalue name\u003d\"textToSay\"\u003e\u003cshadow type\u003d\"text\" id\u003d\"Y2SU%-g(FKV\u003d`:a]252k\"\u003e\u003cfield name\u003d\"TEXT\"\u003etext to say\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"text\" id\u003d\"f]Tej{luk1`Z,WFt@0oR\"\u003e\u003cfield name\u003d\"TEXT\"\u003e\"4 3 3 code received from wall switch. button 2, turn fan off\"\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"deviceSink\"\u003e\u003cshadow type\u003d\"oh_audiosink_dropdown\" id\u003d\"t:.jV?9%wKbh+(A_#YS*\"\u003e\u003cfield name\u003d\"sinks\"\u003echromecast:audiogroup:21632c10-9553-4136-80c3-21202c34e900\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003cvalue name\u003d\"voice\"\u003e\u003cshadow type\u003d\"oh_voices_dropdown\" id\u003d\"13B((NNn@DyqsSsil3,2\"\u003e\u003cfield name\u003d\"voiceName\"\u003e\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003c/block\u003e\u003c/statement\u003e\u003c/block\u003e\u003c/next\u003e\u003c/block\u003e\u003c/statement\u003e\u003cstatement name\u003d\"ELSE\"\u003e\u003cblock type\u003d\"oh_event\" id\u003d\"A$*;~dENElzxbZHis]Ya\"\u003e\u003cfield name\u003d\"eventType\"\u003esendCommand\u003c/field\u003e\u003cvalue name\u003d\"value\"\u003e\u003cshadow type\u003d\"text\" id\u003d\"|Y//qY?rP0+go_f8)~%J\"\u003e\u003cfield name\u003d\"TEXT\"\u003evalue\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"text\" id\u003d\"K`gAusay2z^)3C\u003d$+F0r\"\u003e\u003cfield name\u003d\"TEXT\"\u003eON\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"itemName\"\u003e\u003cshadow type\u003d\"oh_item\" id\u003d\"iDqcH*I!TT($w%/`[,Oi\"\u003e\u003cmutation itemName\u003d\"MyItem\" itemLabel\u003d\"MyItem\"\u003e\u003c/mutation\u003e\u003cfield name\u003d\"itemName\"\u003eMyItem\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003cnext\u003e\u003cblock type\u003d\"controls_if\" id\u003d\"EzU:L]:ulO[bAJ0
L;Uvs\"\u003e\u003cvalue name\u003d\"IF0\"\u003e\u003cblock type\u003d\"logic_compare\" id\u003d\"Fcv6g{$sJ3]8j*HJiUL%\"\u003e\u003cfield name\u003d\"OP\"\u003eEQ\u003c/field\u003e\u003cvalue name\u003d\"A\"\u003e\u003cblock type\u003d\"variables_get\" id\u003d\"-Yp72AJ:`MyFqQ,H!O`d\"\u003e\u003cfield name\u003d\"VAR\" id\u003d\"Xm2sw^F$?X/uE,]2lRWe\"\u003eLogLevel\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"B\"\u003e\u003cblock type\u003d\"math_number\" id\u003d\"C%rF,Bm*RjFsOC%iPq\u003dg\"\u003e\u003cfield name\u003d\"NUM\"\u003e1\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003c/block\u003e\u003c/value\u003e\u003cstatement name\u003d\"DO0\"\u003e\u003cblock type\u003d\"oh_say\" id\u003d\"i%-I,p+$XgV7V(8dg8xY\"\u003e\u003cvalue name\u003d\"textToSay\"\u003e\u003cshadow type\u003d\"text\" id\u003d\"Y2SU%-g(FKV\u003d`:a]252k\"\u003e\u003cfield name\u003d\"TEXT\"\u003etext to say\u003c/field\u003e\u003c/shadow\u003e\u003cblock type\u003d\"text\" id\u003d\"/l[nm?8BxVyhsytECSTv\"\u003e\u003cfield name\u003d\"TEXT\"\u003e\"4 3 3 code received from wall switch. button 2, turn fan off\"\u003c/field\u003e\u003c/block\u003e\u003c/value\u003e\u003cvalue name\u003d\"deviceSink\"\u003e\u003cshadow type\u003d\"oh_audiosink_dropdown\" id\u003d\"3iL4:+/Vla)TVntoX?+)\"\u003e\u003cfield name\u003d\"sinks\"\u003echromecast:audiogroup:21632c10-9553-4136-80c3-21202c34e900\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003cvalue name\u003d\"voice\"\u003e\u003cshadow type\u003d\"oh_voices_dropdown\" id\u003d\"ye0\u003dp*9i%2?hn/`@yyUM\"\u003e\u003cfield name\u003d\"voiceName\"\u003e\u003c/field\u003e\u003c/shadow\u003e\u003c/value\u003e\u003c/block\u003e\u003c/statement\u003e\u003c/block\u003e\u003c/next\u003e\u003c/block\u003e\u003c/statement\u003e\u003c/block\u003e\u003c/statement\u003e\u003c/block\u003e\u003c/next\u003e\u003c/block\u003e\u003c/next\u003e\u003c/block\u003e\u003c/xml\u003e",
            "script": "var startTime, endTime, packet_NUM, LogLevel;\n\n// graalVM\nfunction zdtCompare(zdt1, zdt2, compareOp, precision, compDate) {\n  switch (precision) {\n    case \u0027years\u0027:\n     zdt2 \u003d zdt2.withMonth(zdt1.monthValue());\n    case \u0027months\u0027:\n     zdt2 \u003d zdt2.withDayOfMonth(zdt1.dayOfMonth());\n    case \u0027days\u0027:\n     zdt2 \u003d zdt2.withHour(zdt1.hour());\n    case \u0027hours\u0027:\n     zdt2 \u003d zdt2.withMinute(zdt1.minute());\n    case \u0027minutes\u0027:\n     zdt2 \u003d zdt2.withSecond(zdt1.second());\n    case \u0027seconds\u0027:\n     zdt2 \u003d zdt2.withNano(zdt1.nano());\n  }\n  if (compDate \u003d\u003d\u003d \u0027date\u0027) {\n    zdt1 \u003d zdt1.toLocalDate();\n    zdt2 \u003d zdt2.toLocalDate();\n  } else if (compDate \u003d\u003d\u003d \u0027time\u0027) {\n    zdt1 \u003d zdt1.toLocalTime();\n    zdt2 \u003d zdt2.toLocalTime();\n  }\n  switch (compareOp) {\n    case \u0027before\u0027:\n      return zdt1.isBefore(zdt2);\n    case \u0027equal\u0027:\n      return zdt1.equals(zdt2);\n    case \u0027after\u0027:\n      return zdt1.isAfter(zdt2);\n    case \u0027beforeEqual\u0027:\n      return zdt1.isBefore(zdt2) || zdt1.equals(zdt2);\n    case \u0027afterEqual\u0027:\n      return zdt1.isAfter(zdt2) || zdt1.equals(zdt2);\n  }\n}\n\n\nstartTime \u003d (time.ZonedDateTime.now()).withHour(18).withMinute(0).withSecond(0);\nendTime \u003d (time.ZonedDateTime.now()).withHour(9).withMinute(0).withSecond(0);\nif (packet_NUM \u003d\u003d 2022600 \u0026\u0026 ((time.ZonedDateTime.now()).isBetweenTimes(startTime, endTime))) {\n  if (items.getItem(\u0027MyItem\u0027).state \u003d\u003d \u0027ON\u0027) {\n    items.getItem(\u0027MyItem\u0027).sendCommand(\u0027OFF\u0027);\n    if (LogLevel \u003d\u003d 1) {\n      actions.Voice.say(\u0027\"4 3 3 code received from wall switch. button 2, turn fan off\"\u0027, \u0027\u0027, \u0027chromecast:audiogroup:21632c10-9553-4136-80c3-21202c34e900\u0027);\n    }\n  } else {\n    items.getItem(\u0027MyItem\u0027).sendCommand(\u0027ON\u0027);\n    if (LogLevel \u003d\u003d 1) {\n      actions.Voice.say(\u0027\"4 3 3 code received from wall switch. button 2, turn fan off\"\u0027, \u0027\u0027, \u0027chromecast:audiogroup:21632c10-9553-4136-80c3-21202c34e900\u0027);\n    }\n  }\n}\n",
            "type": "application/javascript"
          },
          "type": "script.ScriptAction"
        }
      ],
      "configuration": {},
      "configDescriptions": [],
      "uid": "blockly",
      "name": "Blockly Scratchpad",
      "tags": [
        "Script"
      ],
      "visibility": "VISIBLE",
      "description": ""
    }
  },

Unfortunately certain characters need to be URL encoded which makes using the raw JSON a little troublesome. But the history is preserved well when checked into git. And the YAML you see on the code tab in MainUI is quite usable. This is a Script so there’s no code tab :-(. But you can see the JS created from the Blockly editor:

var startTime, endTime, packet_NUM, LogLevel;

// graalVM
function zdtCompare(zdt1, zdt2, compareOp, precision, compDate) {
  switch (precision) {
    case 'years':
     zdt2 = zdt2.withMonth(zdt1.monthValue());
    case 'months':
     zdt2 = zdt2.withDayOfMonth(zdt1.dayOfMonth());
    case 'days':
     zdt2 = zdt2.withHour(zdt1.hour());
    case 'hours':
     zdt2 = zdt2.withMinute(zdt1.minute());
    case 'minutes':
     zdt2 = zdt2.withSecond(zdt1.second());
    case 'seconds':
     zdt2 = zdt2.withNano(zdt1.nano());
  }
  if (compDate === 'date') {
    zdt1 = zdt1.toLocalDate();
    zdt2 = zdt2.toLocalDate();
  } else if (compDate === 'time') {
    zdt1 = zdt1.toLocalTime();
    zdt2 = zdt2.toLocalTime();
  }
  switch (compareOp) {
    case 'before':
      return zdt1.isBefore(zdt2);
    case 'equal':
      return zdt1.equals(zdt2);
    case 'after':
      return zdt1.isAfter(zdt2);
    case 'beforeEqual':
      return zdt1.isBefore(zdt2) || zdt1.equals(zdt2);
    case 'afterEqual':
      return zdt1.isAfter(zdt2) || zdt1.equals(zdt2);
  }
}


startTime = (time.ZonedDateTime.now()).withHour(18).withMinute(0).withSecond(0);
endTime = (time.ZonedDateTime.now()).withHour(9).withMinute(0).withSecond(0);
if (packet_NUM == 2022600 && ((time.ZonedDateTime.now()).isBetweenTimes(startTime, endTime))) {
  if (items.getItem('MyItem').state == 'ON') {
    items.getItem('MyItem').sendCommand('OFF');
    if (LogLevel == 1) {
      actions.Voice.say('"4 3 3 code received from wall switch. button 2, turn fan off"', '', 'chromecast:audiogroup:21632c10-9553-4136-80c3-21202c34e900');
    }
  } else {
    items.getItem('MyItem').sendCommand('ON');
    if (LogLevel == 1) {
      actions.Voice.say('"4 3 3 code received from wall switch. button 2, turn fan off"', '', 'chromecast:audiogroup:21632c10-9553-4136-80c3-21202c34e900');
    }
  }
}

I’ve used managed configs exclusively since OH 3.0 and have checked every change I’ve ever made into git. It works well.

1 Like

yeah i could copy paste it out, but it doesn’t get saved under /etc/openhab where all my stuff is saved… but in the jsondb >.>

i build a worklow some years ago which automatically pulls my openhab_conf repo under /etc/openhab as soon as i edit a file. i have all my configs for openhab in there, its super practical ^^

I’m not trying to convince you to change your workflow, but when you use managed configs you don’t need a workflow like this. As soon as you hit save the configs are applied and a backup made. So you’d just need to decide how often/when you want to check in and push the changes to git rather than needing to push all your changes to git in order to deploy a change.

2 Likes

mhhh intresting, i see i need to use the webinterface more…
ill look into it, thanks for the tips :smiley:

I just wanna thank both of you :3

Started to migrate my stuff to ECMA and my sitemaps to pages.

Blocky is not bad and ā€˜kindergarten’ as i thought it would be, but i must confess i don’t have that many rules i can use it with. Cause many of my rules contain xmpp binding stuff and that doesn’t has blocky support rn, but i use that as a template for rules. ECMA is really okay itself if you get the hang of it. I really love that i can use both rule engines at the same time, makes migration way more easier ^^

thanks again for the push… i neglected it so long…

To stay in Blockly for something unsupported like that you can use the inline script block and enter any valid ECMAScript code.

It’s also possible to create a Block Library (Developer Tools → Block Libraries) where you can create your own Blocks that cna be used in your rules. Though that’s a bit more advanced of a feature and requires a good bit on knowledge of how Blockly works. There are a couple useful tutorials on the library and you could use many of the libraries posted to the marketplace.

Speaking of the marketplace, there actuall is a Block library for XMPP on the marketplace already. XMPP Actions

Theoretically, you can install it from Add-on Store → Automation → Block Libraries and once installed you will find it under ā€œLibrariesā€. But this library doesn’t have the ā€œpublishedā€ tag for some reason. If you navigate to Settings → Community Marketplace → Show unpublished entries that should show the XMPP Actions entry in the list.

Once added you’ll see a ā€œLibrariesā€ option on the Blockly screen and you can access the blocks from there (I only have the OHRT Block library installed).

I don’t have xmpp so I can’t test it out myself. But if you test it and let me know if it works I can add the puiblished tag so it’s more widely available.

Okay, this really puzzles me. yeah i saw that link what you posted yesterday, but i don’t see in in my addons:

That’s what i thought its currently not released…

are addons version depended? but i do run 4.2?

But thanks for the tip with the Inline script, didn’t saw that block yesterday, its going to be a huge help

Edit: Okay, i should read your post better, its still unpublished, but now i know how to enable it. thanks!

They can be. Usually it’s best practice to put the versions the library is compatibel with in the title in a special way that is shows up only for those running a version of OH that it works with. This one I suspect will work with any version of OH so lack of a version isn’t that big of a deal.

1 Like