You can try these RulesAPI rules. The rules store the lamp state to the virtual lamp (dimmer) and restore the lamp state from the virtual lamp.
I tested rule using TAustin Virtual Devices V2
Store light state:
{
"name": "vSwitch On > Light Store Level",
"actions": [
{
"if": {
"equals": {
"right": {
"device": {
"devices": [
"-- virtualSwitch ID --"
],
"component": "main",
"capability": "switch",
"attribute": "switch",
}
},
"left": {
"string": "on"
}
},
"then": [
{
"if":
{
"equals": {
"right": {
"device": {
"devices": [
"-- Lamp ID --"
],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "never"
}
},
"left": {
"string": "off"
}
},
"then": [
{
"command": {
"devices": [
"-- virtualDimmer ID --"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"device": {
"devices": [
"-- Lamp ID --"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
}
]
}
]
}
},
{
"command": {
"devices": [
"-- virtualDimmer ID --"
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
],
"else": [
{
"command": {
"devices": [
"-- virtualDimmer ID --"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"device": {
"devices": [
"-- Lamp ID --"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
}
]
}
]
}
},
{
"command": {
"devices": [
"-- virtualDimmer ID --"
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "on"
}
]
}
},
]
}
}
]
}
}
]
}
Restore light state:
{
"name": "vSwitch Off > Light Restore Level",
"actions": [
{
"if": {
"equals": {
"right": {
"device": {
"devices": [
"-- virtualSwitch ID --"
],
"component": "main",
"capability": "switch",
"attribute": "switch"
}
},
"left": {
"string": "off"
}
},
"then": [
{
"if":
{
"equals": {
"right": {
"device": {
"devices": [
"-- virtualDimmer ID --"
],
"component": "main",
"capability": "switch",
"attribute": "switch",
"trigger": "never"
}
},
"left": {
"string": "off"
}
},
"then": [
{
"command": {
"devices": [
"-- Lamp ID --"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"device": {
"devices": [
"-- virtualDimmer ID --"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
}
]
}
]
}
},
{
"sleep": {
"duration": {
"value": {
"integer": 2
},
"unit": "Second"
}
}
},
{
"command": {
"devices": [
"-- Lamp ID --"
],
"commands": [
{
"component": "main",
"capability": "switch",
"command": "off"
}
]
}
}
],
"else": [
{
"command": {
"devices": [
"-- Lamp ID --"
],
"commands": [
{
"component": "main",
"capability": "switchLevel",
"command": "setLevel",
"arguments": [
{
"device": {
"devices": [
"-- virtualDimmer ID --"
],
"component": "main",
"capability": "switchLevel",
"attribute": "level"
}
}
]
}
]
}
}
]
}
}
]
}
}
]
}
Rules are controlled by a virtual switch.