Good day jwj001,
I created a template node for a separated button. It should be a combo button including a v-btn for changing the page and activating dynamic content. The other component is a switch for smart-home control. The goal is to be able to control the power state of a specific lamp without entering the settings page of the device. The data is provided by iobroker.
<div class="so-bs-grid-container">
<v-btn class="so-bs-button" @click="send({payload: provideData(value) })">
Testgerät
</v-btn>
<v-switch class="so-bs-switch" v-model="msg.payload"
active-color="primary"
color="primary"
inset
@update:modelValue="send({payload: provideSwitchData(msg.payload) })">
</v-switch>
</div>
<script>
export default {
data() {
// define variables available component-wide
// (in <template> and component functions)
return {
topic: "alias.0.devices.lights.CompLgt-OG-AZ.General",
}
},
methods: {
provideData: function () {
var message = {
scope: "button",
title: "< OG: Beleuchtung",
page: "lightcontrol.rgb",
topic: this.topic,
};
return message;
},
provideSwitchData: function (switchValue) {
var message = {
scope: "switch",
topic: this.topic + ".Control.ONOFF",
value: switchValue,
};
return message;
},
},
}
</script>
Now the problem is that I can inject the message payload, but if I create a dynamic v-model using the msg.payload, I am not able to define a standard value for it in the data section.
If I try to create a property binding, the application crashes.
How can I define a two-way binding according to a message input and make sure that the latest value of the switch persists, even if I send a message due to a click on the button in the same widget?