Toggle a Shelly Dimmer to last state

Hi,

I have several several Shelly devices. On the Shelly App (Android), I can create widgets that toggle a dimmer between ‘Off’ (0%) and ‘On’ (last state, e.g. 30 %).

When I create an OpenHAB widget, it toggles the dimmer between ‘Off’ (0%) and ‘On’ (100%).

Is there a way to create an OpenHAB widget that toggles the dimmer between ‘Off’ (0%) and ‘On’ (last state)?

I’ve tried to create an ‘Item > Switch’ and created a rule that if the Switch changes to ‘Off’, set Dimmer to ‘Off’ (this works!) and if the Switch changes to ‘On’, set Dimmer to ‘{last state}’ - this doesn’t work. I’ve also created a rule that sets the ‘last state’, but I don’t think this is working (the Number > {last state} remains at Null).

Unfortunately chatgpt hasn’t given me the answer! Has anyone done something similar? I’m using the GUI (yaml code) rather than .items files. I’m using OpenHAB 5 on a Raspberry Pi.

Thanks.

Show what you tried because this approach should work.

The LLMs are basically useless when it comes to openHAB rules. When they managed to produce something that isn’t sheer nonsense, there is always something subtly wrong with the code.

The first think I’d do is make sure that there isn’t setting on the Shelly itself that might help control this. If not, you are on the right track with your rule idea. But a lot can go wrong so without seeing what you tried, it’s no so easy to help figure out what went wrong.

I recommend using Blockly if you are not experienced with programming.

But the overall approach will be:

  1. When an OFF command is sent to the proxy Switch Item (this triggers the rule)
  2. Record the state of the Dimmer before it changed somewhere (in the cache, another Item, etc)
  3. When an ON command is sent to the proxy Switch Item (this is another trigger, perhaps for a different rule)
  4. sendCommand to the Dimmer the state recorded in 2.

Only turn ON/OFF the Dimmer using the proxy switch Item.

In Blockly the code would look something like:

I use shelly dimmer2 and if I send command ON to the brightness Dimmer channel it uses the same brightness as before…:man_shrugging:t3:

Greets