Skip to content

Instantly share code, notes, and snippets.

@ccutrer
Created January 17, 2025 23:37
zigbee2mqtt Events in openHAB
# frozen_string_literal: true
module Inovelli
module Events
BUTTON_UP = "up"
BUTTON_DOWN = "down"
BUTTON_CONFIG = "config"
BUTTON_AUX_UP = "aux_up"
BUTTON_AUX_DOWN = "aux_down"
SINGLE_TAP = "single"
DOUBLE_TAP = "double"
TRIPLE_TAP = "triple"
QUADRUPLE_TAP = "quadruple"
QUINTUPLE_TAP = "quintuple"
HELD = "held"
RELEASE = "release"
end
class << self
def event_info(event)
return unless event.thing.properties["modelId"]&.include?("VZM31-SN")
equipment = event.thing.channels.find(&:link)&.item&.equipment
return unless equipment
button, _, action = event.event.rpartition("_")
[equipment, button, action]
end
def event(name, &block)
id = OpenHAB::DSL::Rules::NameInference.infer_rule_id_from_block(block)
script = block.source
binding = block.binding
OpenHAB::DSL.rule(name, id:, script:, binding:) do
event "openhab/channels/*/triggered", types: "ChannelTriggeredEvent"
run do |event|
data = Inovelli.event_info(event)
next unless data
yield(*data)
end
end
end
end
end
require "inovelli"
Inovelli.event "Room Off (Inovelli)" do |equipment, button, action|
next unless action == Inovelli::Events::DOUBLE_TAP && button == Inovelli::Events::BUTTON_DOWN
next unless equipment.tags.include?("RoomOff")
equipment.location
.equipments(Semantics::Lightbulb)
.members
.points(Semantics::Switch)
.off
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment