Happy new year community,
new year, old problems. I currently prepare the switch from openhabian 2.6 to openhab 3.2, which should run within a Docker container on mit OMV server. For this reason I tried to translate my rules to Blockly. My current task is to write my first Blockly component to control a Hue bulb with the
fadingLightCommand-action, but I have no expierences in JavaScript or Blockly programming.
The hue binding offers the following feature
val hueActions = getActions("hue","hue:0210:00178810d0dc:1")
hueActions.fadingLightCommand("color", new PercentType(100), new DecimalType(1000))
With the Blockly editor I wrote the following component (after reading some tutorials, documentations … well and copy some things from other uesers)
uid: HUE_fading
tags: []
props:
parameters: []
parameterGroups: []
timestamp: Jan 2, 2022, 8:58:05 PM
component: BlockLibrary
config:
name: Block Library c107d09908
slots:
blocks:
- component: BlockType
config:
type: block1
message0: HUE brightness [%] %1 within [ms] %2 with Thing %3
lastDummyAlign0: right
args0:
- type: input_value
name: BRIGHTNESS
- type: input_value
name: FADIING_TIME
text: some text
- type: input_value
name: THING_ID
previousStatement: ""
nextStatement: ""
inputsInline: false
colour: 0
tooltip: ""
helpUrl: ""
slots:
code:
- component: BlockCodeTemplate
config:
template: >
var hueActions = actions.get("hue",{{input:THING_ID}}); hueActions.fadingLightCommand("brightness", {{input:BRIGHTNESS}}, {{input:FADIING_TIME}});
utilities:
- component: UtilityJavaType
config:
javaClass: org.openhab.core.model.script.actions.Things
name: things
The rule, where I use this component looks like. The Idear behind this is to use the Hue fading and override the fading command when the desired brightness is reached … don’t know wheater this will work or not , but this could become an other problem - currently I tried to understand mechanismns.
… but using this Blockly component results in Errors like
==> openhab.log <==
2022-01-02 20:12:54.211 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'aaaa': Fail to execute action: 2
So here are my questions
- I discovered that the expected code line “var things = Java.type(‘org.openhab.core.model.script.actions.Things’);” inside the gererated code will not be generated … why?
- Is the translation of the discriped Hue Binding (in DSL) correctly translated to JavaScript? If not how is the correct translation?
I hope that the experts within this forum might help me. So don’t be quiet, just answer …
Thanks and best regards
Stef