Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uid: commonBlocks
- tags:
- - marketplace:131157
- props:
- parameters: []
- parameterGroups: []
- timestamp: Jul 25, 2023, 10:14:33 AM
- component: BlockLibrary
- config:
- name: Common Blocks
- slots:
- blocks:
- - component: BlockType
- config:
- args0:
- - name: sourceItem
- type: input_value
- - name: targetItem
- type: input_value
- colour: 0
- helpUrl: ""
- inputsInline: false
- message0: Copy state from %1 to %2
- nextStatement: ""
- previousStatement: ""
- tooltip: Will copy current state of first item and send as command to second item
- type: copyItemState
- slots:
- code:
- - component: BlockCodeTemplate
- config:
- template: events.sendCommand({{input:targetItem}}, items.getItem({{input:sourceItem}}).state);
- toolbox:
- - component: PresetInput
- config:
- name: sourceItem
- shadow: true
- type: oh_item
- - component: PresetInput
- config:
- name: targetItem
- shadow: true
- type: oh_item
- - component: BlockType
- config:
- args0:
- - name: notification
- type: input_value
- - name: icon
- type: input_value
- - name: severity
- options:
- - - info
- - info
- - - warning
- - warn
- - - highly important
- - high
- type: field_dropdown
- - default: mail@demo
- name: email
- type: input_value
- colour: 0
- helpUrl: ""
- inputsInline: false
- message0: send notification %1 with icon %2 as %3 to %4
- nextStatement: ""
- previousStatement: ""
- tooltip: Sends a notification via Cloud Connector to one individual recipient including icon and severity
- type: notificationSingleWithIconAndSeverity
- slots:
- code:
- - component: BlockCodeTemplate
- config:
- template: "{{utility:notifications}}.sendNotification({{input:email}}, {{input:notification}}, {{input:icon}}, '{{field:severity}}');"
- toolbox:
- - component: PresetInput
- config:
- fields:
- TEXT: message
- name: notification
- shadow: true
- type: text
- - component: PresetInput
- config:
- fields:
- TEXT: window
- name: icon
- shadow: true
- type: text
- - component: PresetInput
- config:
- fields:
- TEXT: test@example.org
- name: email
- shadow: true
- type: text
- - component: BlockType
- config:
- args0:
- - check: Number
- name: duration
- type: input_value
- - name: duration_unit
- options:
- - - seconds
- - plusSeconds
- - - minutes
- - plusMinutes
- - - hours
- - plusHours
- - - days
- - plusDays
- - - weeks
- - plusWeeks
- - - months
- - plusMonths
- type: field_dropdown
- - check: String
- name: timer_name
- type: input_value
- - default: mail@demo
- name: timer_statement
- type: input_statement
- colour: 0
- helpUrl: https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html
- inputsInline: true
- message0: after %1 %2 do with %3 %4 and keep triggering event-context
- nextStatement: ""
- previousStatement: ""
- tooltip: Schedules a new timer and will pass the event variable as argument to the timer, that you can reuse the initial event during timer execution (e.g. event.itemName)
- type: timerWithInitialEvent
- slots:
- code:
- - component: BlockCodeTemplate
- config:
- template: >
- if (typeof this.timers === 'undefined') {
- this.timers = [];
- }
- if (typeof this.timers[{{input:timer_name}}] === 'undefined' || this.timers[{{input:timer_name}}].hasTerminated()) {
- this.timers[{{input:timer_name}}] = {{utility:scriptExecution}}.createTimerWithArgument({{utility:zdt}}.now().{{field:duration_unit}}({{input:duration}}),event, function (event) {
- {{statements:timer_statement}}
- })
- }
- toolbox:
- - component: PresetInput
- config:
- fields:
- TEXT: MyTimer
- name: timer_name
- shadow: true
- type: text
- - component: PresetInput
- config:
- fields:
- NUM: 10
- name: duration
- shadow: true
- type: math_number
- - component: BlockType
- config:
- args0:
- - check: Number
- name: duration
- type: input_value
- - name: duration_unit
- options:
- - - seconds
- - plusSeconds
- - - minutes
- - plusMinutes
- - - hours
- - plusHours
- - - days
- - plusDays
- - - weeks
- - plusWeeks
- - - months
- - plusMonths
- type: field_dropdown
- - check: String
- name: timer_name
- type: input_value
- - name: timer_statement
- type: input_statement
- - name: reschedule_option
- options:
- - - reschedule
- - this.timers[{{input:timer_name}}].reschedule(zdt.now().{{field:duration_unit}}({{input:duration}}));
- - - cancel
- - >
- this.timers[{{input:timer_name}}].cancel();
- this.timers[{{input:timer_name}}] = undefined;
- - - do nothing
- - //do nothing
- type: field_dropdown
- colour: 0
- helpUrl: https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Event%20Object%20Attributes.html
- inputsInline: true
- message0: after %1 %2 do with %3 %4 %5 if retriggered and keep triggering event-context
- nextStatement: ""
- previousStatement: ""
- tooltip: Schedules a new timer with option to reschedule or cancle and will pass the event variable as argument to the timer, that you can reuse the initial event during timer execution (e.g. event.itemName)
- type: timerWithInitialEventAndOption
- slots:
- code:
- - component: BlockCodeTemplate
- config:
- template: >
- if (typeof this.timers === 'undefined') {
- this.timers = [];
- }
- if (typeof this.timers[{{input:timer_name}}] === 'undefined' || this.timers[{{input:timer_name}}].hasTerminated()) {
- this.timers[{{input:timer_name}}] = {{utility:scriptExecution}}.createTimerWithArgument({{utility:zdt}}.now().{{field:duration_unit}}({{input:duration}}),event, function (event) {
- {{statements:timer_statement}}
- })
- } else {
- {{field:reschedule_option}}
- }
- toolbox:
- - component: PresetInput
- config:
- fields:
- TEXT: MyTimer
- name: timer_name
- shadow: true
- type: text
- - component: PresetInput
- config:
- fields:
- NUM: 10
- name: duration
- shadow: true
- type: math_number
- - component: BlockType
- config:
- args0:
- - name: toggleItem
- type: input_value
- colour: 0
- helpUrl: ""
- inputsInline: false
- message0: Toggle Item %1
- nextStatement: ""
- previousStatement: ""
- tooltip: Will switch an item ON or OFF, depending on current state
- type: toggleItem
- slots:
- code:
- - component: BlockCodeTemplate
- config:
- template: >
- if (items.getItem({{input:toggleItem}}).state == 'ON') {
- events.sendCommand({{input:toggleItem}}, 'OFF');
- } else {
- events.sendCommand({{input:toggleItem}}, 'ON');
- }
- toolbox:
- - component: PresetInput
- config:
- name: toggleItem
- shadow: true
- type: oh_item
- - component: BlockType
- config:
- args0:
- - name: dateTimeItem
- type: input_value
- - name: dateTimeFormat
- type: input_value
- colour: 0
- helpUrl: ""
- inputsInline: false
- message0: Formate datetime item %1 with %2
- output: String
- type: formatDateTime
- slots:
- code:
- - component: BlockCodeTemplate
- config:
- template: time.toZDT(items.getItem({{input:dateTimeItem}})).format(time.DateTimeFormatter.ofPattern({{input:dateTimeFormat}}))
- toolbox:
- - component: PresetInput
- config:
- name: dateTimeItem
- shadow: true
- type: oh_item
- - component: PresetInput
- config:
- fields:
- TEXT: HH:mm
- name: dateTimeFormat
- shadow: true
- type: text
- utilities:
- - component: UtilityJavaType
- config:
- javaClass: org.openhab.io.openhabcloud.NotificationAction
- name: notifications
- - component: UtilityJavaType
- config:
- javaClass: org.openhab.core.model.script.actions.ScriptExecution
- name: scriptExecution
- - component: UtilityJavaType
- config:
- javaClass: java.time.ZonedDateTime
- name: zdt
- - component: UtilityJavaType
- config:
- javaClass: java.time.format.DateTimeFormatter
- name: dtf
Add Comment
Please, Sign In to add comment