sendCommand/postUpdate z-wave switch

I have two physical switches (z-wave ZDB5100). I want to control a dimmable light. When pressing button1 it should turn on the light to 10%, when pressing button2 it should be set to 100%. I would the switches to reflect the mode, so if pressing button1 and then button2 the light should be at 100%, button1 off and button2 on.

I have created a rule to support this, but I have to react on changed events to have it triggered when pressing the buttons. Is it expected behavior that physically pushing buttons does not cause commands to be send? I was hoping I could use received command, so that I could post updates to the other button without triggering the rule.

I am using habapp, but the issue should be the same for rules:

    def __init__(self):
        super().__init__()

        # Setup items
        self.BedroomSwitch1 = SwitchItem.get_item('BedroomSwitch1')
        self.BedroomSwitch2 = SwitchItem.get_item('BedroomSwitch2')
        self.ColorLedSwitch_1 = SwitchItem.get_item('ColorLedSwitch_1')
        self.ColorLedBrightness_1 = DimmerItem.get_item('ColorLedBrightness_1')
        self.ColorLedTemperature_1 = DimmerItem.get_item('ColorLedTemperature_1')

        # Trigger on item updates
        self.listen_event(self.BedroomSwitch1.name, self.BedroomSwitch1_changed, ItemStateChangedEvent)
        self.listen_event(self.BedroomSwitch2.name, self.BedroomSwitch2_changed, ItemStateChangedEvent)
        
    def BedroomSwitch1_changed(self, event):
        if self.BedroomSwitch1.is_on():
            if self.ColorLedTemperature_1.value != 50:
                self.openhab.send_command(self.ColorLedTemperature_1, "50")
            if self.ColorLedBrightness_1.value != 1:
                self.openhab.send_command(self.ColorLedBrightness_1, "1")
            if self.ColorLedSwitch_1.is_off():
                self.openhab.send_command(self.ColorLedSwitch_1, "ON")
        elif self.BedroomSwitch1.is_off():
            self.openhab.send_command(self.ColorLedSwitch_1, "OFF")
            
        if self.BedroomSwitchColor2.is_on():
            self.openhab.post_update(self.BedroomSwitchColor2, "OFF")

    def BedroomSwitch2_changed(self, event):
        if self.BedroomSwitch2.is_on():
            if self.ColorLedTemperature_1.value != 50:
                self.openhab.send_command(self.ColorLedTemperature_1, "50")
            if self.ColorLedBrightness_1.value != 100:
                self.openhab.send_command(self.ColorLedBrightness_1, "100")
            if self.ColorLedSwitch_1.is_off():
                self.openhab.send_command(self.ColorLedSwitch_1, "ON")
        elif self.BedroomSwitch2.is_off():
            self.openhab.send_command(self.ColorLedSwitch_1, "OFF")

        if self.BedroomSwitchColor1.is_on():
            self.openhab.post_update(self.BedroomSwitchColor1, "OFF")

Standard openHAB model, commands originate from rules or UI, state updates originate from incoming data.
Always exceptions of course, and some bindings allow for generation of OH commands derived from data from say a control panel.
zwave is not one of those bindings.

You might look into the follow profile

I solved my problem by looking at the states instead, but it seems a better approach only to trigger rules when needed, so I would like to understand the profiles. It is a bit out of my comfort zone, so bear with me. I tried two configurations:

Switch Switch1 {channel="zwave:xxx:node5:switch_binary1" [profile="follow"]}
Switch Switch1 {channel="zwave:xxx:node5:switch_binary1", channel="zwave:xxx:node5:switch_binary2" [profile="follow"]}

but none of them would trigger a rule with received command whether I pushed Switch1 or Switch2.

Clearly those Item defs make no sense both at the same time.
When experimenting like that, beware caching effects. Minor edits often seem to get missed.

The profile operates on the channel, and changes its behaviour.
The follow profile transforms an Item update into an Item command.

Normal events, device data → binding → channel → Item state update
Follow, device data → binding → channel → Item command

Any other channels/bindings on the target Item will see that command just as though it came from UI or rules, and do any usual sending to device.
You “lose” the ordinary update from the profiled channel, and might want other channels for that.
It only operates on that channel, other updates from other chanels or rules remain unaffected.
Take care if cross-linking devices with two profiles, high risk of creating a loop.

In short …

looks legit to me.

The two lines were not used at the same time, but were different experiments I made. The follow profile does sound like what I am looking for, I just need to make it work. Should the first version also work? So without any link between the two buttons, apart from what the rule does. With that, a push of the button would send a command to the switch that I could trigger on with a received command.
.items:

Switch Switch1 {channel="zwave:xxx:node5:switch_binary1" [profile="follow"]}

.rules:

rule TestZwaveSwitch
    when
        Item Switch1 received command
    then
        logInfo("Switch1", "Switch1 received command")
    end

This doesn’t work. I can see the z-wave messages and the item updates in the sitemap, but the rule is not triggered. Actually, the rule doesn’t get triggered even if it is set to trigger on “changed”, but if I remove the profile, it triggers on “changed”, but not on “received command”. Does this make sense?

Right, I completely messed up with follow description, got it all about face, sorry. Always get this backwards.
Let’s try again.

The profile operates on the channel, and changes its behaviour.
The follow profile transforms an Item update into a channel command.

Normal events,

device data -> binding -> channel -> Item state update
There may be multiple channels, each updating the Item

OH command -> Item -> channel -> binding -> device directive
There may be multiple channels, each directing devices

OH update (rule, UI, or other channel) -> Item state update
Ignored by bindings.

Effect of follow profile
OH update (rule, UI, or other channel) -> Item -> channel with follow profile -> binding treats update as command -> device directive
(there is no command on OH event bus to trigger rules, it’s a private affair inside the channel)

So, you’d use a follow profile to make a device follow the state of an Item.

In your case, the principle would be -

WallSwitchItem … normal zwave channel A plus follow channel B
LampItem … normal zwave channel B

When you waggle the wallswitch and its corresponding Item gets updated, channel B will command the lamp.
I hope!

Note that changes to the lamp, whether autonomously or by OH command from rule or UI, will not get to the “wallswitch” device.

That fits what I’m seeing better :slight_smile:

The light I am controlling is a RGB, WW, CW LED setup controlled by custom MQTT, so I don’t want/can’t link that directly to the switches. I made it work checking the states in the rule, so I will continue down that road. I learned a lot about the channel universe which I will have to check out further.

I really appreciate you taking the time to help, so thank you, rossko57.

1 Like