Chenges a Dimmer Item over a time while a Button/Item is ON and stops with the release of this Button (Item changes to OFF). If the Dimmer is near its maximum or minimum (0 or 100) it changes dimm direktion.
Language: Blocky
Dependencies: Blocky
Changelog
Version 0.1
- initial release
Resources
uid: bass:dimmer
label: physical Button Dimmer
description: dimms a light up and down until a button is released
configDescriptions:
- name: dimmer
label: Dimmer Item
required: true
type: TEXT
context: item
filterCriteria:
- name: type
value: Dimmer
- name: button
label: Button Item
description: Button Item witch is Hold while Dimming
required: true
type: TEXT
context: item
filterCriteria:
- name: type
value: Switch
- name: speed
label: Time between dimmersteps
description: Default 0.5 Seconds
required: false
type: DECIMAL
defaultValue: 0.5
- name: steps
label: Stepsize
description: Default 2
required: false
type: INTEGER
defaultValue: 2
triggers:
- id: "1"
configuration:
itemName: "{{button}}"
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
blockSource: <xml
xmlns="https://developers.google.com/blockly/xml"><variables><variable
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</variable></variables><block
type="controls_if" id="hf|iyj^45,2Dk$rY`L#u" x="316" y="85"><mutation
else="1"></mutation><value name="IF0"><block type="oh_get_value"
id=")_FQIYOrZE9G#)?{KVQi"><value name="key"><shadow type="text"
id="R7TOKtE^_E1Hm.1:oIEG"><field
name="TEXT">Dimmrichtung</field></shadow></value></block></value><statement
name="DO0"><block type="oh_store_value" id="W%IO|,~KL~cFZoM}h:U)"><value
name="value"><shadow type="text"><field
name="TEXT">False</field></shadow><block type="logic_boolean"
id="%e+ry^YZ7H2zjpo..5m8"><field
name="BOOL">FALSE</field></block></value><value name="key"><shadow
type="text" id="oAb^d6}[:+Mbq3s5aY{`"><field
name="TEXT">Dimmrichtung</field></shadow></value></block></statement><statement
name="ELSE"><block type="oh_store_value"
id=";0-U=n@l2gd$fr:jfVT^"><value name="value"><shadow type="text"><field
name="TEXT">False</field></shadow><block type="logic_boolean"
id=".,aipr6Sf?.?ZKsaIW9~"><field
name="BOOL">TRUE</field></block></value><value name="key"><shadow
type="text" id="=D?0y!-]i;1pqnu-jBg]"><field
name="TEXT">Dimmrichtung</field></shadow></value></block></statement><next><block
type="variables_set" id="a+j{HO=+LS|7y*r|ztx@"><field name="VAR"
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field><value name="VALUE"><block
type="oh_getitem_state" id="mKPr=.+@-?2vm))Hk_G+"><value
name="itemName"><shadow type="oh_item" id="Mn(#N5Q,7-f}ri2H{%zh"><field
name="itemName">{{dimmer}}</field></shadow></value></block></value><next><block
type="oh_timer" id="(w)!r{JN~/ivy6QAwyOc"><field
name="delayUnits">plusSeconds</field><value name="delay"><shadow
type="math_number" id="(Cnwl]]!@p^LgTRW,b@#"><field
name="NUM">0.001</field></shadow></value><value name="timerName"><shadow
type="text" id="V}nEK#Y@J4Z=%FXX$[SV"><field
name="TEXT">TDim</field></shadow></value><statement
name="timerCode"><block type="controls_if"
id="mQyHZ_F){$=~}Xw|Bc)E"><mutation else="1"></mutation><value
name="IF0"><block type="oh_get_value" id="+]HZNoHBp-*-k`osleC6"><value
name="key"><shadow type="text" id="]B+7Jjm;}-eb},XZ~*+h"><field
name="TEXT">Dimmrichtung</field></shadow></value></block></value><statement
name="DO0"><block type="variables_set" id="NGay|uc4}l=LU_EWYV.8"><field
name="VAR" id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field><value
name="VALUE"><block type="math_arithmetic"
id="Z;XD:pHHp/wN:aTr}K(N"><field name="OP">ADD</field><value
name="A"><shadow type="math_number" id="12@tp`)/EfaoQjKNSagp"><field
name="NUM">1</field></shadow><block type="variables_get"
id="{+T]/b4=%.re#ID1NdnS"><field name="VAR"
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field></block></value><value
name="B"><shadow type="math_number" id="!PEn{3v%(Djksw]HRP::"><field
name="NUM">{{steps}}</field></shadow></value></block></value></block></statement><statement
name="ELSE"><block type="variables_set" id="q+1Jz`uwgRaY$4DW~ilo"><field
name="VAR" id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field><value
name="VALUE"><block type="math_arithmetic"
id="JY-81}}[,6Xm|qaa^yKp"><field name="OP">MINUS</field><value
name="A"><shadow type="math_number"><field
name="NUM">1</field></shadow><block type="variables_get"
id="B9;k{zZ~pF^%P([^vf3_"><field name="VAR"
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field></block></value><value
name="B"><shadow type="math_number" id="X@]~-~sXKvcv0ENWXvu9"><field
name="NUM">{{steps}}</field></shadow></value></block></value></block></statement><next><block
type="controls_if" id="VspV+~dNtU|p!741kZ4+"><mutation
elseif="1"></mutation><value name="IF0"><block type="logic_compare"
id="o(n=!do@@a6=A^(oJI.4"><field name="OP">GT</field><value
name="A"><block type="variables_get" id="~P?TG5_l2gT9t~K.5,H~"><field
name="VAR"
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field></block></value><value
name="B"><block type="math_number" id="n%22HMrFZ?s$F,d,2Ib9"><field
name="NUM">97</field></block></value></block></value><statement
name="DO0"><block type="oh_store_value" id="nCehfmA`9{aJ9S)b7c@a"><value
name="value"><shadow type="text" id="JOmn)5iIb(6+t,R)|*z!"><field
name="TEXT">False</field></shadow><block type="logic_boolean"
id="o/F;BxKolqZl*Vzw[:Nz"><field
name="BOOL">FALSE</field></block></value><value name="key"><shadow
type="text" id="{GyXqtf-+`nVtVI,6.8Y"><field
name="TEXT">Dimmrichtung</field></shadow></value></block></statement><value
name="IF1"><block type="logic_compare" id="rS,MUm8!Z:3u3~,4B(cN"><field
name="OP">LT</field><value name="A"><block type="variables_get"
id="XPHgG[/BF:GkQQ*`dxH9"><field name="VAR"
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field></block></value><value
name="B"><block type="math_number" id="L,6HMK1*w#IKps}/QKau"><field
name="NUM">3</field></block></value></block></value><statement
name="DO1"><block type="oh_store_value" id="Oo:X13+0DkyFhU9qfupC"><value
name="value"><shadow type="text"><field
name="TEXT">False</field></shadow><block type="logic_boolean"
id="#%E?kHS!TQA_P@7ar:ts"><field
name="BOOL">TRUE</field></block></value><value name="key"><shadow
type="text" id="{7s;Z82}~/[4Ez1-)$G("><field
name="TEXT">Dimmrichtung</field></shadow></value></block></statement><next><block
type="oh_event" id="~pt}Qn#|@^EWNGg1=I%`"><field
name="eventType">sendCommand</field><value name="value"><shadow
type="text" id="1fXIJx]497(P0*nBQEM~"><field
name="TEXT">value</field></shadow><block type="variables_get"
id="E$|ThcPH|61%@I0#[2aB"><field name="VAR"
id="F:]C,gbymhOzxnha)Zx0">Helligkeit</field></block></value><value
name="itemName"><shadow type="oh_item" id="PB-xlaP8h;{.T+K3+T1:"><field
name="itemName">{{dimmer}}</field></shadow></value><next><block
type="controls_if" id="(m3wo?W?g#b|3Tm2Gxh."><mutation
else="1"></mutation><value name="IF0"><block type="logic_compare"
id="2f,EG!0%J;29f=JYo7Rm"><field name="OP">EQ</field><value
name="A"><block type="oh_getitem_state" id="f:0/DhU?)=wrFWwhTWX%"><value
name="itemName"><shadow type="oh_item" id="oYsDkJFaLv!fV6dg~6n%"><field
name="itemName">{{button}}</field></shadow></value></block></value><value
name="B"><block type="text" id="Icd;wP6?{VlMtcCU*`5S"><field
name="TEXT">OFF</field></block></value></block></value><statement
name="DO0"><block type="oh_timer_cancel"
id="Tg%XLSO=G%-_pYTV#)z,"><value name="timerName"><shadow type="text"
id="7/erlQ,zro,*:)T_m#S~"><field
name="TEXT">TDim</field></shadow></value></block></statement><statement
name="ELSE"><block type="oh_timer_reschedule"
id="S`j.=cIyBRCj;D3+yYMZ"><field
name="delayUnits">plusSeconds</field><value name="delay"><shadow
type="math_number" id="~(Lz||~w//ISv=a^#|M["><field
name="NUM">{{speed}}</field></shadow></value><value name="timerName"><shadow
type="text" id=":P443SP^W$YMvPhYp3gu"><field
name="TEXT">TDim</field></shadow></value></block></statement></block></next></block></next></block></next></block></statement></block></next></block></next></block></xml>
type: application/javascript
script: >
var Helligkeit;
if (typeof this.storedValues === 'undefined') {
this.storedValues = [];
}
var scriptExecution = Java.type('org.openhab.core.model.script.actions.ScriptExecution');
var zdt = Java.type('java.time.ZonedDateTime');
if (typeof this.timers === 'undefined') {
this.timers = [];
}
if (this.storedValues['Dimmrichtung']) {
this.storedValues['Dimmrichtung'] = false;
} else {
this.storedValues['Dimmrichtung'] = true;
}
Helligkeit = itemRegistry.getItem('{{dimmer}}').getState();
if (typeof this.timers['TDim'] === 'undefined' || this.timers['TDim'].hasTerminated()) {
this.timers['TDim'] = scriptExecution.createTimer(zdt.now().plusSeconds(0.001), function () {
if (this.storedValues['Dimmrichtung']) {
Helligkeit = Helligkeit + {{steps}};
} else {
Helligkeit = Helligkeit - {{steps}};
}
if (Helligkeit > 97) {
this.storedValues['Dimmrichtung'] = false;
} else if (Helligkeit < 3) {
this.storedValues['Dimmrichtung'] = true;
}
events.sendCommand('{{dimmer}}', Helligkeit);
if (itemRegistry.getItem('{{button}}').getState() == 'OFF') {
if (typeof this.timers['TDim'] !== 'undefined') {
this.timers['TDim'].cancel();
this.timers['TDim'] = undefined;
}
} else {
if (typeof this.timers['TDim'] !== 'undefined') { this.timers['TDim'].reschedule(zdt.now().plusSeconds({{speed}})); }
}
})
}
type: script.ScriptAction