I’ve just opened a PR to support creating a trigger profile in JRuby. (State profiles are already supported).
Once it’s merged, you can create your own trigger profile and use it like this:
String vSetLightConfig_Kitchen {channel="mqtt:topic:test:test" [ profile="ruby:trigger_button_cycle", event="3001", values="NORMAL,REDUCED,EVENING,NIGHT" ], channel="otherchannel...."}
To create the profile in JRuby:
# frozen_string_literal: true
profile(:trigger_button_cycle) do |event, trigger:, item:, configuration:|
if event == :trigger_from_handler && (configuration["event"].nil? || configuration["event"] == trigger)
next unless (values = configuration["values"])
values = values.split(",").map(&:strip).compact
current = values.index(item.state.to_s) || -1
new_value = values[current + 1] || values.first
item.command new_value
end
end
Essentially, this lets you create whatever profile you want to do whatever you wish, without needing to wait for someone else to come along and create a profile / addon for you. You can whip one up quickly using a jruby script.
PS The above ruby profile is only usable in file-based .items file. If you want to use it on UI based items, simply add a label and config description, e.g.:
# frozen_string_literal: true
config_description = config_description do
parameter :event, :text, label: "Trigger Event",
description: "React when this event occurs. When not supplied, react to any event."
parameter :values, :text, label: "Values", description: "A comma separated list of values to cycle through"
end
profile(:trigger_button_cycler, label: "Cycle through states on trigger",
config_description:) do |event, trigger:, item:, configuration:|
if event == :trigger_from_handler && (configuration["event"].nil? || configuration["event"] == trigger)
next unless (values = configuration["values"])
values = values.split(",").map(&:strip).compact
current = values.index(item.state.to_s) || -1
new_value = values[current + 1] || values.first
item.command new_value
end
end