«
Automation is executed in run blocks
type | name | label | state |
---|---|---|---|
Switch | TestSwitch | Test Switch | OFF |
rule 'Access Event Properties' do
<trigger> TestSwitch
run do |event|
logger.info("#{event.item.id} triggered to #{event.state}")
end
end
trigger | |
---|---|
updated | |
changed |
rule 'Access Event Properties' do
changed TestSwitch
run { |event| logger.info("#{event.item.id} triggered from #{event.was} to #{event.state}") }
end
rule 'Multi Line Run Block' do
changed TestSwitch
run do |event|
logger.info("#{event.item.id} triggered")
logger.info("from #{event.was}") if event.was
logger.info("to #{event.state}") if event.state
end
end
rule 'Multiple Run Blocks' do
changed TestSwitch
run { |event| logger.info("#{event.item.id} triggered") }
run { |event| logger.info("from #{event.was}") if event.was }
run { |event| logger.info("to #{event.state}") if event.state }
end
rule 'log event state info' do
updated TestSwitch
run do |event|
logger.info("event is null: #{event.null?}")
logger.info("event is undef: #{event.undef?}")
logger.info("event state?: #{event.state?}")
logger.info("event state: #{event.state.inspect}")
end
end
updated_state | null | undef | |
---|---|---|---|
NULL | true | false | |
UNDEF | false | true |
rule 'log event state info' do
changed TestSwitch
run do |event|
logger.info("event state: #{event.null?} #{event.undef?} #{event.state?} #{event.state.inspect}")
logger.info("event was: #{event.was_null?} #{event.was_undef?} #{event.was?} #{event.was.inspect}")
end
end
initial_state | updated_state | new_null | new_undef | new_state_p | new_state | was_null | was_undef | was_state_p | was_state | |
---|---|---|---|---|---|---|---|---|---|---|
ON | NULL | true | false | false | nil | false | false | true | ON | |
ON | UNDEF | false | true | false | nil | false | false | true | ON | |
NULL | ON | false | false | true | ON | true | false | false | nil | |
UNDEF | ON | false | false | true | ON | false | true | false | nil |