Dimming a light globe

G’day all, is there a better way to dim a globe than this?

{
    "name": "Test Dimming over 1 minute",
    "actions": [
        {
            "if": {
                "equals": {
                    "left": {
                        "string": "on"
                    },
                    "right": {
                        "device": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "component": "main",
                            "capability": "switch",
                            "attribute": "switch",
                            "trigger": "Always"
                        }
                    }
                },
                "then": [
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switchLevel",
                                    "command": "setLevel",
                                    "arguments": [
                                        {
                                            "integer": 30
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 10
                                },
                                "unit": "Second"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switchLevel",
                                    "command": "setLevel",
                                    "arguments": [
                                        {
                                            "integer": 25
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 10
                                },
                                "unit": "Second"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switchLevel",
                                    "command": "setLevel",
                                    "arguments": [
                                        {
                                            "integer": 20
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 10
                                },
                                "unit": "Second"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switchLevel",
                                    "command": "setLevel",
                                    "arguments": [
                                        {
                                            "integer": 15
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 10
                                },
                                "unit": "Second"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switchLevel",
                                    "command": "setLevel",
                                    "arguments": [
                                        {
                                            "integer": 10
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 10
                                },
                                "unit": "Second"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switchLevel",
                                    "command": "setLevel",
                                    "arguments": [
                                        {
                                            "integer": 5
                                        }
                                    ]
                                }
                            ]
                        }
                    },
                    {
                        "sleep": {
                            "duration": {
                                "value": {
                                    "integer": 10
                                },
                                "unit": "Second"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": [
                                "c47536d9-bf37-4995-9dee-87f31e9d9100"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switch",
                                    "command": "off"
                                }
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

I’ve thought of maybe using an if statement so that if setlevel is >= 0 then setlevel = level -5 but can’t get anything to work

Cheers, Geoff

Otherwise, is there a way to use the attribute of another device as the level that i wish to set the globe to? I have the counter utility from @TAustin and i was wondering if i could loop the action and each time decrease the count by a set amount and then use this number as the setlevel value.

If you use this driver

You can use level steps

You can also use level steps from Rules API

  {
	"command": {
	  "devices": [
		"device-id"
	  ],
	  "commands": [
		{
		  "component": "main",
		  "capability": "legendabsolute60149.levelSteps",
		  "command": "setLevelSteps",
		  "arguments": [{"decimal": -10.0 }]
		}
	  ]
	}
  }

If you perform this action every ten seconds then you might be able to do the action you want.

2 Likes

hey TapioX, thanks for this. I actually already use the Zigbee Light Multifunction Mc driver for my Ikea globes. Unfortunately the lights I wish to dim are hue lights and these have been brought into ST with Philips Hue Beta edge driver by @blueyetisoftware so I can’t use the multifunction driver.

I didn’t know about the setLevelSteps command so I’ll have a play with it as I think it will work somewhat. Ideally it would be nice to use an every command like:

If: switch turns off
Then:
If: Level >10
Then: ever X seconds, setLevelStep -10.0 until Level <10

I get the feeling that something like this can be done in the rules API though or else there would most likely be an example of how to dim lights somewhere.

I also believe that that the every command can’t be nested so it would have to be in its own rule dedicated to a specific device. I’m also not sure that there is a good way to exit the every command once the light level reaches my desired end point. @nayelyz
posted a code in this thread Rules API exit from every loop? but it seems to remove the rule completely. also, if I took this approach I would have to somehow call a rule from a rule which again, I don’t know if this can be done.

1 Like

I haven’t looked up this post, but I think I remember the example, where the “límit” function was used with the value “Lifetime”, which then eliminates the rule. But you can use the value you need e.g.

“limit”: {
“count”: 1,
“period”: “Day”,
“actions”:[…]

I have only used this with the buttons on the remote control. With one button I have been able to increase the dimming by 10% and with the other button to decrease the dimming by 10%.

Thanks all for the ideas. I wrote them up in a script but as the every command cant be nested it cant be used say when a switch state is changed (e.g. if switch state changes then every 10 seconds do something). Unless I can have a dedicated dimming rule that I can call from another rule or unless I can use another deviceID parameter as my level value in the setlevel argument then I cant think of any other way to achieve a dimming light through the API. this is very annoying as setting lights to do things is one of the main reasons people initially take up the smart home hobby and I would have thought dimming gradually to an off state would be front and centre for things that should be achievable.

As you say we can’t nest the “every” function, and although the every “specific” has a workaround I don’t know of a way to do that with every “interval”.
Have you taken a look at @TAustin 's Timer Utility?

Don’t know exactly what you need to achieve but I’ve found it useful.

Hey John, I have the timer utility. I’m just trying to work out if I can use it in some way. I think for now I’ll just have to stick to adding steps and pauses in a rule unfortunately. If I could call a rule from a rule I Could make a separate rule that set the current level and then ever x seconds dropped the level by 5 or 10 until the level was below 10 or something but I don’t think I can do that.

@Geoff18
I’ve just been trying this out, more for interest than any need to use it. I don’t know how you want to implement this but with @TAustin 's brilliant utility it can be done.
Was pleasantly surprised to find that the numerical counter values and lighting level can be written one to another. (This is not always the case as there is null documentation on arguments - I have a report open on this on another thread).

{
 "name": "Test to run Timer to subtract and dim Tablelight finally switching off",
 "actions": [
  {
   "if": {
    "greaterThanOrEquals": {
     "left": {
      "device": {
       "devices": [
        "Timer Utility"
       ],
       "component": "counter",
       "capability": "partyvoice23922.count",
       "attribute": "count",
       "trigger": "Always"
      }
     },
     "right": {
      "integer": 1
     },
     "aggregation": "Any",
     "changesOnly": true
    },
    "then": [
     {
      "command": {
       "devices": [
        "Timer Utility"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "switch",
         "command": "on"
        },
        {
         "component": "counter",
         "capability": "partyvoice23922.subtract2",
         "command": "push"
        }
       ],
       "sequence": {
        "commands": "Serial",
        "devices": "Serial"
       }
      }
     },
     {
      "command": {
       "devices": [
        "Light"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "switchLevel",
         "command": "setLevel",
         "arguments": [
          {
           "device": {
            "devices": [
             "Timer Utility"
            ],
            "component": "counter",
            "capability": "partyvoice23922.count",
            "attribute": "count"
           }
          }
         ]
        }
       ]
      }
     }
    ],
    "else": [
     {
      "command": {
       "devices": [
        "Light"
       ],
       "commands": [
        {
         "component": "main",
         "capability": "switch",
         "command": "off"
        }
       ]
      }
     }
    ],
    "sequence": {
     "then": "Parallel",
     "else": "Serial"
    }
   }
  }
 ]
}

You can run this by pressing the ‘Counter Reset’ on the utilty or running this

{
 "name": "Test to use TableLight current level to reset Timer count value",
 "actions": [
  {
   "command": {
    "devices": [
     "Timer Utility"
    ],
    "commands": [
     {
      "component": "counter",
      "capability": "partyvoice23922.resetnum",
      "command": "resetValue",
      "arguments": [
       {
        "device": {
         "devices": [
          "Light"
         ],
         "component": "main",
         "capability": "switchLevel",
         "attribute": "level"
        }
       }
      ]
     }
    ]
   }
  }
 ]
}

while the speed of dimming can be controlled as the ‘Counter Incremnet/Decrement’ on the utility.

1 Like

Hey John,

thank you so much for this. this is a great work around and I’ll definitely be trying to implement it in the lighting scene I’m trying to make. This is exactly what I needed as a way to dim my hue lights.

for some reason though, the hue lamp that I’m trying to dim to nothing is actually dimming to 1% new in 2% increments over about 2 minutes. I have no idea why its doing it as there are no rules or routines associated with the lamp that could be causing it. i have also looked in all the settings in the Hue, Alexa and google apps and there is nothing in there that should be dimming the lamp. The only thing i can think of is that my AT app updated and now I have lighting groups and once a light is in the group it allows dimming over a set time. I did put the lamp in a group to try it but it did not allow the lamp to be dimmed at a set colour and would only allow me to set a white warmth value. I deleted the lighting group but for some reason, when I trigger the routine that the lighting group had been associated with, it dims my lamp from the set level down to 1%. if it is not this causing the lamp to dim then I have no idea what is causing it to all of a sudden dim.

I haven’t tried anything more with this as I wasn’t really much concerned about using it - I use more IKEA bulbs, which with @Mariano_Colmenarejo 's Multifunction driver can dim off on a standard setting.
I can only think of, when using the changes function in a rule on several lights to synchronise level, everything is OK if they are all switched on - if one is off it will be switched on. Then maybe if your timer utility is still on ( maybe need to switch it off ) it dims off?
Sorry Geoff but I can’t imagine anything else now.

I figured out another way, its a bit janky though because it dims in 20% steps and the minimum dim time is 5 minutes. ST added a lighting group option in the last update I received and this has the ability to dim a group of lights to off over a set time. I thought all my problems were solved but it has its drawbacks. for some reason it forces the globes to be set to a white colour and there was no way to avoid this and this didn’t work for me as I have my globes set to a dim purple before bed. It also only works if the lights are set up as a group of 2 or more and it forces the lights to start and end the dimming at the same level %. I only need to dim 1 lamp so to get around this I guess I’ll just use a second virtual light so I can make a group. To get around the forcing the globes to be white issue I copied and pasted the code from the rule into postman and removed all the “type” commands as well as the colour temperature command. At least now its a simple rule to dim the lights and it runs locally. this is what I ended up with:

{
    "name": "Test ceiling light dimming by ST lighting group control",
    "actions": [
        {
            "if": {
                "equals": {
                    "left": {
                        "device": {
                            "devices": [
                                "d0d73f4e-8a86-46f4-a546-0a3a0c3206e1"
                            ],
                            "component": "main",
                            "capability": "switch",
                            "attribute": "switch",
                            "trigger": "Always"
                        }
                    },
                    "right": {
                        "string": "off"
                    },
                    "changesOnly": false
                },
                "then": [
                    {
                        "command": {
                            "devices": [
                                "75024922-466d-4d9d-93a4-0949c6218f11"
                            ],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "synthetic.lightingEffectFade",
                                    "command": "setFade",
                                    "arguments": [
                                        {
                                            "map": {
                                                "duration": {
                                                    "integer": 5
                                                },
                                                "effects": {
                                                    "array": {
                                                        "operands": [
                                                            {
                                                                "map": {
                                                                    "capability": {
                                                                        "string": "switchLevel"
                                                                    },
                                                                    "start": {
                                                                        "integer": 100
                                                                    },
                                                                    "end": {
                                                                        "integer": 1
                                                                    }
                                                                }
                                                            }
                                                        ]
                                                    }
                                                },
                                                "fadeType": {
                                                    "string": "WindDown"
                                                },
                                                "state": {
                                                    "string": "Run"
                                                },
                                                "afterAction": {
                                                    "map": {
                                                        "timeZoneId": {
                                                            "string": "Australia/Sydney"
                                                        },
                                                        "afterActionType": {
                                                            "string": "TurnOff"
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    ]
                                }
                            ]
                        }
                    }
                ],
                "sequence": {
                    "then": "Parallel",
                    "else": "Parallel"
                }
            }
        }
    ]
}

Oh and I found out why my lamps were dimming on their own…I set up a sharptools rule to dim them and forgot id done it :sweat_smile:

2 Likes

I made similar rule but in CLI listing is “executionLocation”: “Cloud”
So rule is not running locally for me.