Error with Blockly generated code since Openhab 5.1

Hi,

i’ve a Blockly part in the “But only if” section in some rules, which doesn’t work since upgrade from Openhab 5.0 to 5.1.

The openhab.log shows this entry for all rules with these Blockly part:

2026-01-03 14:18:00.730 [ERROR] [ernal.handler.ScriptConditionHandler] - Script of rule with UID 'lueft-kg-auto-immer-ho-off' did not return a boolean value, but '[object Object]'

This is the Blockly part:

grafik

This is the complete YAML of the rule:

configuration: {}
triggers:
  - id: "1"
    configuration:
      cronExpression: 0 0/1 * * * ?
    type: timer.GenericCronTrigger
conditions:
  - inputs: {}
    id: "5"
    configuration:
      blockSource: <xml xmlns="https://developers.google.com/blockly/xml"><block
        type="logic_compare" id="OWYM#^9llsfC/LnnE0de" x="202" y="586"><field
        name="OP">EQ</field><value name="A"><block type="oh_get_zdt_part"
        id="q^V0_WJutE~@~vD?}H#j"><field
        name="temporalPart">getHour</field><value name="zdt"><shadow
        type="oh_zdt" id="gxmVcXf@M+u9G6~-I%r^"><field
        name="day">2025-04-30</field></shadow><block type="oh_zdt_now"
        id="`g;#LzK/w9[GRr!5WC=M"></block></value></block></value><value
        name="B"><block type="oh_getitem_attribute"
        id="jvV5d5Y/$w^Gm[(q/*IA"><mutation
        attributeName="NumericState"></mutation><field
        name="attributeName">NumericState</field><value name="item"><shadow
        type="oh_getitem" id="9tc}kv{)w^s4dbW;,Q,G"><value
        name="itemName"><shadow type="oh_item"
        id="f~w5aqmFL;[F`(I@V;#i"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow></value></shadow><block
        type="oh_getitem" id="2|qu^7(A,,*H1w+~Jalw"><value
        name="itemName"><shadow type="oh_item"
        id="f~w5aqmFL;[F`(I@V;#i"><mutation itemName="MyItem"
        itemLabel="MyItem"></mutation><field
        name="itemName">MyItem</field></shadow><block type="oh_item"
        id="97v$fiyqZ}#K+%sXYxNP"><mutation itemName="homeofficeLueftungKGoff"
        itemLabel="Wochentags (Homeoffice)"></mutation><field
        name="itemName">homeofficeLueftungKGoff</field></block></value></block></value></block></value></block></xml>
      type: application/javascript
      script: >
        ((time.ZonedDateTime.now()).hour()) ==
        items.getItem('homeofficeLueftungKGoff').numericState;
    type: script.ScriptCondition
  - inputs: {}
    id: "4"
    configuration:
      itemName: Lueftung_Modus_KG
      operator: =
      state: "0"
    type: core.ItemStateCondition
  - inputs: {}
    id: "7"
    configuration:
      itemName: Bueronutzung
      operator: =
      state: "1"
    type: core.ItemStateCondition
  - inputs: {}
    id: "2"
    configuration:
      offset: 0
    type: ephemeris.WeekdayCondition
  - inputs: {}
    id: "8"
    configuration:
      offset: 0
    type: ephemeris.NotHolidayCondition
actions:
  - inputs: {}
    id: "3"
    configuration:
      command: OFF
      itemName: gLueftungenKG
    type: core.ItemCommandAction

It works, when I change the “script” part under ID5 to:

Boolean(((time.ZonedDateTime.now()).hour()) == items.getItem(‘homeofficeLueftungKGoff’).numericState);

I don’t want to edit the Blockly code manually…
Can anyone give me a tip on how to solve this properly?

Thanks,
Huaba

Hi,
Try using a variable as a workaround.

var Ergebnis;
Ergebnis = ((time.ZonedDateTime.now()).hour()) == 16;
Ergebnis;

Hi and thanks, the workaround seems to be working.

I think you can also add a return block to return the result of the evaluation.

Yes and no. Wrapping must then be activated in the Javascript settings or no variables may be used so far due to an error.

var Ergebnis;

"use wrapper;"


Ergebnis = ((time.ZonedDateTime.now()).hour()) == 16;
return Ergebnis

Adding ‘use wrapper’ or ‘use wrapper=true’ (semicolons can be added) as the first or second line enables the wrapper.

I’ve created a fix that ensures directives are always at the top:

1 Like