Can I make a Rule where if the brightness of a light dimmer changes then a lamp brightness will match the light dimmer? Without having to make a long list of if elses
try using Smart lighting (if it is available in your region)
Automations > Discover (icon to right of + in upper left of Automations screen) > Smart lighting
use the sync feature
Cool thank you. I didn’t even know that was there.
Someone else would need to answer your question in regards to Rules API
Is it a Z-Wave device? If so, you can use Association Groups.
Hi, @Sixoul
Here’s an example of a Rule to make the mirror effect:
In that case, the use case is with the Switch capability but you should be able to do it with switchLevel as well.
Here’s another example using the capability of “colorControl”:
Would this be possible to get two switches to match each other as well? The dimmer works but the switch has on and off. Would it be using changes as well? When I attempted that it resulted in some odd behaviour of cycling between the two states
Is not z-wave.
Can you share an example of what you tried to do, please?
Yes, when you have two devices each mirroring each other, then you end up creating a race condition which results in the cycling behavior you see. Not sure of the Rules syntax, but in a Routine, I would check the state of the other device by making it a precondition. So, I would have something like:
If Switch 1 is off (precondition)
Switch 2 turns on
then
Turn on Switch 1
If Switch 1 is on (precondition)
Switch 2 turns off
then
Turn off Switch 1
And you’d need another set of Rules or Routines for Switch 1 controlling Switch 2.
I took the first example and changed the light, switch commands to main, switch and turned the device to dimmer-2. This is one of the similar issues I had with a normal routine as well. I thought changes would fix the issue. If the dimmer1 is on level 2 and dimmer2 is on level 2, then dimmer 1 is changed to level 3 when it changes dimmer2 to level 3 for some reason dimmer1 will change back to level 2. I believe it’s a race condition.
{
"name":"Mirror switch events of main and light components",
"actions":[
{
"if":{
"changes":{
"equals":{
"left":{
"device":{
"devices":[
"Dimmer-1"
],
"component":"main",
"capability":"switch",
"attribute":"switch"
}
},
"right":{
"string":"on"
}
}
},
"then":[
{
"command":{
"devices":[
"Dimmer-2"
],
"commands":[
{
"component":"main",
"capability":"switch",
"command":"on"
}
]
}
}
],
"else":[
{
"if":{
"changes":{
"equals":{
"left":{
"device":{
"devices":[
"Dimmer-1"
],
"component":"main",
"capability":"switch",
"attribute":"switch"
}
},
"right":{
"string":"off"
}
}
},
"then":[
{
"command":{
"devices":[
"Dimmer-2"
],
"commands":[
{
"component":"main",
"capability":"switch",
"command":"off"
}
]
}
}
]
}
}
]
}
},
{
"if":{
"changes":{
"equals":{
"left":{
"device":{
"devices":[
"Dimmer-2"
],
"component":"main",
"capability":"switch",
"attribute":"switch"
}
},
"right":{
"string":"on"
}
}
},
"then":[
{
"command":{
"devices":[
"Dimmer1"
],
"commands":[
{
"component":"main",
"capability":"switch",
"command":"on"
}
]
}
}
],
"else":[
{
"if":{
"changes":{
"equals":{
"left":{
"device":{
"devices":[
"Dimmer-2"
],
"component":"main",
"capability":"switch",
"attribute":"switch"
}
},
"right":{
"string":"off"
}
}
},
"then":[
{
"command":{
"devices":[
"Dimmer-1"
],
"commands":[
{
"component":"main",
"capability":"switch",
"command":"off"
}
]
}
}
]
}
}
]
}
}
]
}
You need to have precondition checks as I mentioned in my previous post else you will get race conditions.
I saw that after I posted and have set up the preconditions. Thank you.
NP…happy to help.
For the dimmer switchLevel example would a precondition be something along the lines of
If Switch2 did NOT change(precondition)
Switch 1 changes light level
then
Change Switch 2 light level
That might work. Have to give it a try I guess
I had an issue where my dimmer lights randomly turned off then on then off again. At 9:29 I noticed it but it seems to happen multiple times. At 9:30 I had to turn them on. Is it my rule?
Can you share the rule to check it?
{
"name": "Living Room Dimmer Rules",
"actions":[
{
"if": {
"and": [
{
"equals": {
"left": {
"device": {
"devices": ["Switch1"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Never"
}
},
"right": {
"string": "off"
}
}
},
{
"changes": {
"equals": {
"left": {
"device": {
"devices": ["Switch2"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Always"
}
},
"right": {
"string": "on"
}
}
}
}
],
"then": [
{
"command": {
"devices": ["Switch1"],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "on"
}
]
}
}
]
}
},
{
"if": {
"and": [
{
"equals": {
"left": {
"device": {
"devices": ["Switch1"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Never"
}
},
"right": {
"string": "on"
}
}
},
{
"changes": {
"equals": {
"left": {
"device": {
"devices": ["Switch2"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Always"
}
},
"right": {
"string": "off"
}
}
}
}
],
"then": [
{
"command": {
"devices": ["Switch1"],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
]
}
},
{
"if": {
"and": [
{
"equals": {
"left": {
"device": {
"devices": ["Switch2"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Never"
}
},
"right": {
"string": "off"
}
}
},
{
"changes": {
"equals": {
"left": {
"device": {
"devices": ["Switch1"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Always"
}
},
"right": {
"string": "on"
}
}
}
}
],
"then": [
{
"command": {
"devices": ["Switch2"],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "on"
}
]
}
}
]
}
},
{
"if": {
"and": [
{
"equals": {
"left": {
"device": {
"devices": ["Switch2"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Never"
}
},
"right": {
"string": "on"
}
}
},
{
"changes": {
"equals": {
"left": {
"device": {
"devices": ["Switch1"],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "Always"
}
},
"right": {
"string": "off"
}
}
}
}
],
"then": [
{
"command": {
"devices": ["Switch2"],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
]
}
}
]
}