«
Rule languages has ensure_states feature
| type | name | function |
|---|---|---|
| Dimmer | Dimmers | AVG |
| type | name | label | group | state |
|---|---|---|---|---|
| Dimmer | DimmerOne | Dimmer One | Dimmers | 50 |
| Dimmer | DimmerTwo | Dimmer Two | Dimmers | 50 |
| Number:Temperature | Temp | Temp [%d °F] | 80 |
| item | state |
|---|---|
| DimmerOne | <initial_state> |
rule "command received" do
<trigger_type> DimmerOne
run do |event|
logger.info("DimmerOne <trigger_type>")
end
end
DimmerOne.ensure.<command>| initial_state | command | final_state | trigger_type | |
|---|---|---|---|---|
| 0 | on | 100 | received_command | |
| 0 | << ON | 100 | received_command | |
| 0 | update(ON) | 100 | updated | |
| 0 | << 50 | 50 | received_command | |
| 0 | update(50) | 50 | updated | |
| 50 | off | 0 | received_command | |
| 50 | << OFF | 0 | received_command | |
| 50 | update(OFF) | 0 | updated | |
| 50 | << 100 | 100 | received_command | |
| 50 | update(100) | 100 | updated | |
| 100 | off | 0 | received_command | |
| 100 | << OFF | 0 | received_command | |
| 100 | << 0 | 0 | received_command | |
| 100 | update(0) | 0 | updated | |
| 100 | update(OFF) | 0 | updated |
| item | state |
|---|---|
| DimmerOne | <initial_state> |
rule "command received" do
<trigger_type> DimmerOne
run do |event|
logger.info("DimmerOne <trigger_type>")
end
end
DimmerOne.ensure.<command>
logger.info("Command sent")| initial_state | command | final_state | trigger_type | |
|---|---|---|---|---|
| 0 | off | 0 | received_command | |
| 0 | << OFF | 0 | received_command | |
| 0 | << 0 | 0 | received_command | |
| 0 | update(OFF) | 0 | updated | |
| 0 | update(0) | 0 | updated | |
| 50 | on | 50 | received_command | |
| 50 | << ON | 50 | received_command | |
| 50 | << 50 | 50 | received_command | |
| 50 | update(50) | 50 | updated | |
| 100 | on | 100 | received_command | |
| 100 | << ON | 100 | received_command | |
| 100 | << 100 | 100 | received_command | |
| 100 | update(100) | 100 | updated |
| item | state |
|---|---|
| DimmerOne | <initial_state1> |
| DimmerTwo | <initial_state2> |
rule "command received" do
received_command DimmerOne
run do |event|
logger.info("DimmerOne received command")
end
end
Dimmers.ensure.<command>| initial_state1 | initial_state2 | command | final_state1 | final_state2 | |
|---|---|---|---|---|---|
| 0 | 0 | on | 100 | 100 | |
| 0 | 0 | << ON | 100 | 100 | |
| 0 | 0 | << 50 | 50 | 50 | |
| 50 | 0 | off | 0 | 0 | |
| 50 | 0 | << OFF | 0 | 0 | |
| 50 | 0 | << 100 | 100 | 100 |
| item | state |
|---|---|
| DimmerOne | <initial_state1> |
| DimmerTwo | <initial_state2> |
rule "command received" do
received_command DimmerOne
run do |event|
logger.info("DimmerOne received command")
end
end
Dimmers.ensure.<command>
logger.info("Command sent")| initial_state1 | initial_state2 | command | final_state1 | final_state2 | |
|---|---|---|---|---|---|
| 0 | 0 | off | 0 | 0 | |
| 0 | 0 | << OFF | 0 | 0 | |
| 100 | 0 | << 50 | 100 | 0 |
| item | state |
|---|---|
| DimmerOne | <initial_state1> |
| DimmerTwo | <initial_state2> |
rule "command received" do
received_command DimmerOne
run do |event|
logger.info("DimmerOne received command")
end
end
Dimmers.members.ensure.<command>| initial_state1 | initial_state2 | command | final_state1 | final_state2 | |
|---|---|---|---|---|---|
| 0 | 100 | on | 100 | 100 | |
| 0 | 100 | << ON | 100 | 100 | |
| 0 | 100 | << 50 | 50 | 50 |
| item | state |
|---|---|
| DimmerOne | 0 |
rule "command received" do
<trigger_type> DimmerOne
run do |event|
logger.info("DimmerOne <trigger_type>")
end
end
ensure_states do
DimmerOne.<command>
end
logger.info("Command sent")| command | trigger_type | |
|---|---|---|
| off | received_command | |
| update(OFF) | updated |
| type | name | state |
|---|---|---|
| Switch | Switch1 | <initial_state> |
rule "command received" do
<trigger_type> Switch1
run do |event|
logger.info("Switch1 <trigger_type>")
end
end
Switch1.ensure.<command>
logger.info("Command sent")| initial_state | command | trigger_type | |
|---|---|---|---|
| OFF | command false | received_command | |
| ON | command true | received_command | |
| OFF | update false | updated | |
| ON | update true | updated |
| type | name | state |
|---|---|---|
| Switch | Switch1 | OFF |
rule "command received" do
received_command Switch1
run do |event|
logger.info("Switch1 received command")
end
end
Switch1.ensure.update ON
logger.info("Item updated")rule "command received" do
received_command DimmerOne, DimmerTwo
run do |event|
logger.info("Dimmers received command")
end
end
sleep 1
[DimmerOne, DimmerTwo].ensure.command <command>| command | should | |
|---|---|---|
| 50 | should not | |
| 10 | should |
Temp.ensure << 75
sleep 1
logger.info("Temp is #{Temp.state}")