This commit is contained in:
Koen Kanters
2019-04-24 20:59:06 +02:00
parent 32b76edb7c
commit 21dc1a8c8e
+30 -1
View File
@@ -313,6 +313,22 @@ const configurations = {
temperature_command_topic: true,
},
},
// Fan
'fan': {
type: 'fan',
object_id: 'fan',
discovery_payload: {
state_topic: true,
state_value_template: '{{ value_json.fan_state }}',
command_topic: true,
command_topic_postfix: 'fan_state',
speed_state_topic: true,
speed_command_topic: true,
speed_value_template: '{{ value_json.fan_mode }}',
speeds: ['off', 'low', 'medium', 'high', 'on', 'auto', 'smart'],
},
},
};
const switchWithPostfix = (postfix) => {
@@ -735,7 +751,7 @@ class HomeAssistant {
// Set json_attributes_topic for types which support this
// https://github.com/Koenkk/zigbee2mqtt/issues/840
if (['binary_sensor', 'sensor', 'lock', 'climate'].includes(config.type)) {
if (['binary_sensor', 'sensor', 'lock', 'climate', 'fan'].includes(config.type)) {
payload.json_attributes_topic = payload.state_topic;
}
@@ -782,6 +798,11 @@ class HomeAssistant {
}
payload.command_topic += 'set';
if (payload.command_topic_postfix) {
payload.command_topic += `/${payload.command_topic_postfix}`;
delete payload.command_topic_postfix;
}
}
if (payload.set_position_topic && payload.command_topic) {
@@ -804,10 +825,18 @@ class HomeAssistant {
payload.temperature_state_topic = stateTopic;
}
if (payload.speed_state_topic) {
payload.speed_state_topic = stateTopic;
}
if (payload.temperature_command_topic) {
payload.temperature_command_topic = `${stateTopic}/set/occupied_heating_setpoint`;
}
if (payload.speed_command_topic) {
payload.speed_command_topic = `${stateTopic}/set/fan_mode`;
}
// Override configuration with user settings.
if (device.hasOwnProperty('homeassistant')) {
const add = (obj) => {