@insleys
This is an interesting problem that is similar to something I’ve had to deal with for reading thermostat temperatures, so some thoughts are below.
A possible work-around, providing you are willing to accept a slightly limited set of brightness values, could be as follows (I’m assuming that your lights have brightness values ranging from 10-1000 for their “Bright value v2”-- if they use 1-100 then adjust the logic accordingly):
Define a numeric variable ‘light_brightness’ and a boolean variable ‘record_light_brightness’ (initially TRUE)
Set up the following Tuya conditions that use ‘inside range’ and are set to trigger a logicblock when the light brightness changes to be within a certain range.
Condition, range
- bright1, 10-100
- bright2, 100-200
- bright3, 200-300
- …
- bright10, 900-1000
Set up a further condition ‘is_recording_brightness’ that depends on whether ‘record_light_brightness’ is TRUE.
Set up the following logicblocks
Logicblock, triggers
- handle_bright1, bright1 and is_recording_brightness
- handle_bright2, bright2 and is_recording_brightness
- …
- handle bright10, bright10 and is_recording_brightness
Each logicblock is only triggered if the brightness is within the defined range, and only if ‘is_recording_brightness’ is TRUE. For each logicblock, update the variable light_brightness using a webhook to an appropriate level. So, for handle_bright2 you could set it to 150, etc.
When your door sensor triggers “open”, first set ‘recording_brightness’ to FALSE (to prevent further updates to ‘light_brightness’), then change the lamp brightness to the level you require.
When the door sensor triggers “closed”, set ‘recording_brightness’ to TRUE. You then need to restore the saved value for 'light_brightness. However, here we have an issue as although you can set the brightness level of the Tuya light to any allowed explicit value, you cannot pass a variable value direct.
You can, however, get around this using IFTTT providing you can also set the light brightness from IFTTT. Create an IFTTT aplet that is triggered from Apilio and passes the ‘light_brightness’ value (pass as “{{light_brightness}}” in the advanced option settings in the Apilio IFTTT call). Then use this value within IFTTT to set the light brightness. If you call this IFTTT aplet from Apilio as the final step in the logicblock that triggers when the door sensor is closed, then you should get the effect you desire. The slight latency when calling IFTTT would not be a major issue here as it would only occur when the door sensor closes.
The granularity of the light brightness could be varied depending on how many conidtions and logicblocks you want to use. I’ve suggested 10, but you could increase this if you wished.
**Note for @pebneter **: it would be really helpful if Tuya devices could be passed a value that derives from a variable, rather than needing an explicit value. So, for example in this instance, if a Tuya light could be passed a value such as “{{light_brightness}}” (as you can do when passing values via IFTTT) then you would not need to go via IFTTT to set this.