I'd really like to be able to specify separate fade times for on vs off in motion lighting. In my setup, I'd like the lights to come on instantly (0 fade), but use a fade time of several seconds when turning off.
Unless I'm missing something, I don't think this is currently possible but it would be a very appreciated addition to motion lighting.
If you are always wanting the same fade in/out settings you can typically set those on the device in the driver with settings or parameters on a command. If the driver doesn't have that capability there may be a custom community driver for the device that does.
If you want to do it programmatically then you won't be able to use motion lighting. You might be able to use Rule Machine but you will also be hard-pressed to make it work in one rule. You might have two rules; one that, for example, at 6:00 pm sets the fade in time to 3 seconds and at 6:00 am sets the fade in time to 0. And then one that just does the motion lighting. Or you can continue to use the motion lighting app.
The reason I say you may need to break it out into two apps is because, if you try to change the fade time programmatically right before you turn it on or off there is no guarantee that it will have taken the parameter before you turn it on or off so you might not see the change until the next time it turns on or off.
This honestly shouldnt be any issue at all. If you are fading off then your faded to 0 before being turned off. when turned on the light will be at level 0. So issue a On level 100 command to turn on instantly and a fade to 0 then off command for turning off.
Basically in rule machine
set switch x to on
set dimmer x to 100
On no motion
(delay if any)
fade dimmer x to 0 over x seconds
set switch x to off delay x seconds to allow fade to fiinsh
I had to use rule machine for motion lighting exactly because you can't set fade time.
In rule machine I can set fade time to 1 second when turning on and have a fade time of 5 seconds when turning off. I've only done this with the Inovelli bulbs and dimmers, but I'm guessing that it probably works with other devices also.
It can be an issue depending on what is going on already on the hub and the device. If you are calling a command on the device to change the ramp rate or ramp steps (which will result in a Z-Wave message to change a parameter on the device) and you are also turning the switch on or off (to take advantage of that new ramp rate or ramp steps you sent) the hub will create two instances of the driver for that; one for each Z-Wave command. There is no guarantee one will finish before the other as far as I can tell. You might actually see the command to change the switch state happen before the command to change ramp rate/ramp steps.
So, if you are using a hardware capability to fade then there is no guarantee. If I had to guess from your pseudo-code there is a software fade as a single command in RM. If that's the case then, sure, order is guaranteed but so is the fade not working very well because it's done in software and it's my experience that software fades are typically horrendously choppy and unsatisfactory.
For Tasmota, which is what @anon62731458 is using, there is a ramp-up/ramp-down command, it is implemented in the firmware of the device. It does have some limitations and is not perfect with all kinds of lights, but it does a nice job of it. It is not implemented in HE.
With Tasmota, when turning on, the level goes up to 10 if it was below 10 when turning off, not sure if this is the best approach, but I think it makes sense.