1st, thank you much for taking time to digest and give me info and answers. The info on processing complexity is useful and interesting.
2nd, I apologize if in what I’m asking below you have already directly answered, I have tried to grok your statements and I think I am still seeing something unexpected. If I am wrong, please tell me so, my feelings will not be hurt =)
3rd, apologies for the length, at this point, I need to paste in some concrete examples to allow for explicit confirm/deny.
So… below are 2 examples directly generated by my app using minimal configured options so they are as simple as possible. Surely there is still noise in these I can try to boil down absolute minimum layers for simplicity, but I do not have a harness or code manipulated to allow simpler rule generation or submission, and I am leaning toward hard examples at this point.
I anonymized the device-ids and a couple other specifics, but the rules are otherwise in-tact and submit successfully to the rules API. An easier way to pick them apart is probably an online JSON tool like: JSON Parser Online to parse JSON
Example 1
- WORKS: action[0] fires in time-range, action[1] fires all the time when motion ceases. NOTE: this disproved my original theory a little as I see the action not associated with a time-range firing always
{
"name": "app-<myappidhere>-rule",
"actions": [
{
"if": {
"and": [
{
"between": {
"value": {
"time": {
"reference": "Now"
}
},
"start": {
"time": {
"reference": "Noon",
"offset": {
"value": {
"integer": -300
},
"unit": "Minute"
}
}
},
"end": {
"time": {
"reference": "Noon",
"offset": {
"value": {
"integer": 360
},
"unit": "Minute"
}
}
}
}
},
{
"or": [
{
"equals": {
"left": {
"device": {
"devices": [
"<motion-device-id-here>"
],
"component": "main",
"capability": "motionSensor",
"attribute": "motion"
}
},
"right": {
"string": "active"
}
}
}
]
},
{
"equals": {
"left": {
"device": {
"devices": [
"<switch-device-id-here>"
],
"component": "main",
"capability": "switch",
"attribute": "switch"
}
},
"right": {
"string": "off"
}
}
}
],
"then": [
{
"command": {
"devices": [
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"integer": 50
},
{
"integer": 20
}
]
}
]
}
}
]
}
},
{
"if": {
"then": [
{
"command": {
"devices": [
"<switch-device-id-here>",
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
],
"and": [
{
"equals": {
"left": {
"device": {
"devices": [
"<motion-device-id-here>"
],
"component": "main",
"capability": "motionSensor",
"attribute": "motion"
}
},
"right": {
"string": "inactive"
}
}
}
]
}
}
]
}
EXAMPLE 2
- FAILS:
- action[0] fires in time-range
- action[1] never fires, regardless of time-range
- action[2] never fires (has no time range associated with it)
- action[3] seems to work, harder to test but saw it fire in at least one test
{
"name": "app-<myappidhere>-rule",
"actions": [
{
"if": {
"and": [
{
"between": {
"value": {
"time": {
"reference": "Now"
}
},
"start": {
"time": {
"reference": "Noon",
"offset": {
"value": {
"integer": -300
},
"unit": "Minute"
}
}
},
"end": {
"time": {
"reference": "Noon",
"offset": {
"value": {
"integer": 360
},
"unit": "Minute"
}
}
}
}
},
{
"or": [
{
"equals": {
"left": {
"device": {
"devices": [
"<motion-device-id-here>"
],
"component": "main",
"capability": "motionSensor",
"attribute": "motion"
}
},
"right": {
"string": "active"
}
}
}
]
},
{
"equals": {
"left": {
"device": {
"devices": [
"<switch-device-id-here>"
],
"component": "main",
"capability": "switch",
"attribute": "switch"
}
},
"right": {
"string": "off"
}
}
}
],
"then": [
{
"command": {
"devices": [
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"integer": 50
},
{
"integer": 20
}
]
}
]
}
}
]
}
},
{
"if": {
"and": [
{
"between": {
"value": {
"time": {
"reference": "Now"
}
},
"start": {
"time": {
"reference": "Noon",
"offset": {
"value": {
"integer": 360
},
"unit": "Minute"
}
}
},
"end": {
"time": {
"reference": "Noon",
"offset": {
"value": {
"integer": -300
},
"unit": "Minute"
}
}
}
}
},
{
"or": [
{
"equals": {
"left": {
"device": {
"devices": [
"<motion-device-id-here>"
],
"component": "main",
"capability": "motionSensor",
"attribute": "motion"
}
},
"right": {
"string": "active"
}
}
}
]
},
{
"equals": {
"left": {
"device": {
"devices": [
"<switch-device-id-here>"
],
"component": "main",
"capability": "switch",
"attribute": "switch"
}
},
"right": {
"string": "off"
}
}
}
],
"then": [
{
"command": {
"devices": [
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"integer": 15
},
{
"integer": 20
}
]
}
]
}
}
]
}
},
{
"if": {
"then": [
{
"command": {
"devices": [
"<switch-device-id-here>",
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
],
"and": [
{
"equals": {
"left": {
"device": {
"devices": [
"<motion-device-id-here>"
],
"component": "main",
"capability": "motionSensor",
"attribute": "motion"
}
},
"right": {
"string": "inactive"
}
}
}
]
}
},
{
"every": {
"specific": {
"reference": "Noon",
"offset": {
"value": {
"integer": 360
},
"unit": "Minute"
}
},
"actions": [
{
"if": {
"or": [
{
"equals": {
"left": {
"device": {
"devices": [
"<switch-device-id-here>"
],
"component": "main",
"capability": "switch",
"attribute": "switch"
}
},
"right": {
"string": "on"
}
}
}
],
"then": [
{
"command": {
"devices": [
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
},
{
"command": {
"devices": [
"<switch-device-id-here>"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"integer": 15
},
{
"integer": 20
}
]
}
]
}
}
]
}
}
]
}
}
]
}
In summary, rule 1 is intended to be:
- [0]: between 7AM and 6:30PM (iirc), turn on lights with motion, setting dim levels for some
- [1]: _anytime_ turn off lights with no action
In summary, rule 2 is intended to be:
- [0]: between 7AM and 6:30PM, turn on lights with motion, setting dim levels for some (day)
- [1]: between 6:30PM and 7AM, turn on (different) lights with motion, setting dim levels for some (night)
- [2]: _anytime_ turn off lights with no motion
- [3]: at 6:30PM, transition lights from 'day' to 'night'
I don’t think this conflicts with your original assertion. Rules 0,1 are conditioned every minute to confirm in range. Rule 3 is checked ‘every’ minute to see if condition matches’ but rule 2 should not be associated with the other time constraints.
If you think my rules are defining something else just call me out.
Again thank everyone for any time you put into helping me here. In worst case scenario I can probably fall back to creating 2 independent rules, it’s still less than the original 4.