Reading switch state prior to trigger?

I’ve got a room with two lights, one on a wall switch and one on a dimmer module. I would like to be able to use the wall switch to toggle the dimmer conditionally. So, if the wall switch is already on and I press the On switch, toggle the state of the dimmer module.

I know I can make a scene that performs Luup code when a switch is pressed, but I don’t know how to tell if the light was already on before the switch was pressed. Is this possible?

If a Z-Wave switch is on, pressing on again will not normally result in any command being sent.

If you have room in the wall-box, you could use a dual switch and fit a micro-module to act as a remote control for the dimmer.