First … thanks to @rlkoshak and @ysc (who answers to my “old” thread https://community.openhab.org/t/copy-of-blockly-rules/130953/5
I rewrote my Blockly component to the following (based on some examples I found in this forum … thx to the authors)
uid: HUE_fading
tags: []
props:
parameters: []
parameterGroups: []
timestamp: Jan 2, 2022, 8:58:59 PM
component: BlockLibrary
config:
name: Block Library c107d09908
slots:
blocks:
- component: BlockType
config:
type: HUE_fading
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: >
{{utility:things}}.getActions('hue',{{input:THING_ID}}).fadingLightCommand('color', {{input:BRIGHTNESS}}, {{input:FADIING_TIME}});
utilities:
- component: UtilityJavaType
config:
name: things
javaClass: org.openhab.core.model.script.actions.Things
Also my Rule was modified to this to excute the new component only once
This all generates the following code which look good for me:
var dimTime, brightness;
var things = Java.type('org.openhab.core.model.script.actions.Things');
dimTime = 2500;
if (itemRegistry.getItem('Mod_20_EG_WC_Relais2_Hue_Brightness').getState() == 'ON') {
if (itemRegistry.getItem('HUEWC_Helligkeit').getState() == '0') {
print('Brightness = 0 --> ramp up to 100% ');
brightness = 100;
} else {
print('Brightness <> 0 --> ramp downto 0%');
brightness = 0;
}
things.getActions('hue','hue:group:02648f68d9:14').fadingLightCommand('color', brightness, dimTime);
} else if (itemRegistry.getItem('Mod_20_EG_WC_Relais2_Hue_Brightness').getState() == 'OFF') {
print('Relais released --> stop dimming and freeze brightness');
events.sendCommand('HUEWC_Helligkeit', itemRegistry.getItem('HUEWC_Helligkeit').getState());
}
print('* Exit Rule ----------------------------------------');
But the call of this Rule will results again in:
==> openhab.log <==
2022-01-03 19:11:18.466 [ERROR] [e.automation.internal.RuleEngineImpl] - Failed to execute rule 'aaaa': Fail to execute action: 2
From my point of view (well, a less educated guess), the JS code looks good - I got back
var things = Java.type('org.openhab.core.model.script.actions.Things');
But when I look to the action I’m not shure if the quotes at ‘hue’, the thing-ID ‘hue:group:02648f68d9:14’ and '‘color’ too are correct. Is there a significant difference between ’ and " ?
things.getActions('hue','hue:group:02648f68d9:14').fadingLightCommand('color', brightness, dimTime);
If yes it would be easy to change ‘hue’ to “hue”, but I don’t know how to change this for the thing-ID … but maybe this is not the problem.
When we look at the error message … “fail to execute action: 2” … is here a usefull hind burried? My assumption is, that the fadingLightCommand has a problem. In the HUE Binding discription the parameters brightness and dimTime has special types … could this be a problem?