@SerializedName("state_topic")
protected @Nullable String stateTopic;
+ @SerializedName("command_template")
+ protected @Nullable String commandTemplate;
@SerializedName("command_topic")
protected String commandTopic = "";
@SerializedName("payload_on")
componentConfiguration.getUpdateListener())
.stateTopic(channelConfiguration.stateTopic, channelConfiguration.getValueTemplate())
.commandTopic(channelConfiguration.commandTopic, channelConfiguration.isRetain(),
- channelConfiguration.getQos())
+ channelConfiguration.getQos(), channelConfiguration.commandTemplate)
.build();
}
}
assertPublished("zigbee2mqtt/fan/set/state", "ON_");
}
+ @SuppressWarnings("null")
+ @Test
+ public void testCommandTemplate() throws InterruptedException {
+ var component = discoverComponent(configTopicToMqtt(CONFIG_TOPIC), """
+ {
+ "availability": [
+ {
+ "topic": "zigbee2mqtt/bridge/state"
+ }
+ ],
+ "device": {
+ "identifiers": [
+ "zigbee2mqtt_0x0000000000000000"
+ ],
+ "manufacturer": "Fans inc",
+ "model": "Fan",
+ "name": "FanBlower",
+ "sw_version": "Zigbee2MQTT 1.18.2"
+ },
+ "name": "fan",
+ "payload_off": "OFF_",
+ "payload_on": "ON_",
+ "state_topic": "zigbee2mqtt/fan/state",
+ "command_topic": "zigbee2mqtt/fan/set/state",
+ "command_template": "set to {{ value }}"
+ }
+ """);
+
+ assertThat(component.channels.size(), is(1));
+
+ component.getChannel(Fan.SWITCH_CHANNEL_ID).getState().publishValue(OnOffType.OFF);
+ assertPublished("zigbee2mqtt/fan/set/state", "set to OFF_");
+ }
+
@Override
protected Set<String> getConfigTopics() {
return Set.of(CONFIG_TOPIC);