Mqtt and smart plug / generic power socket


I just discovered Nymea and I am pleasantly surprised by the user interface and the ease of scripting.
My nymea:core instance is running on a kubernetes cluster under Arm64.
I have a number of zigbee devices, which are all managed from zigbee2mqtt. So all status and commands are accessible from an MQTT server (also in K8S) for OpenHab for example.

I have several Bosch smart plugs, and I have some difficulties to control them but also to synchronize their state (on/off) with generic power socket things.

The generic power socket does not have a “pressed” event that could be triggered when it is activated in the user interface.
I have tried to use a virtual power switch, which has this event, but I can’t synchronize the states of the two components (virtual power switch and generic power socket). It seems that the “pressed” event is also triggered when the value is changed and not just when the button is pressed. This generates a kind of loop in the end of ON/OFF/ON/OFF/… commands.

I can receive MQTT messages from the smart plug several times a second depending on the power consumption.

Could someone please help me to find a solution?



I’m not 100% sure if I understand the problem correctly, but I think you can use

ThingState {
    thingId: "..." // generic power socket
    stateName: "power"
    onValueChanged: {
        console.log("Generic power socket has been turned", value == true ? "on" : "off")

Is that what you’re asking for?


Yes it works.
The missing piece is to synch the generic power socket state when the device is controlled manually.

Thanks a lot.

You can assign something to ‘value’ too