Skip to content

Commit

Permalink
fix: Use light dimmers for sound switch volume #254
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Feb 21, 2020
1 parent 3d66d4e commit 3a08226
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
15 changes: 15 additions & 0 deletions hass/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,21 @@ module.exports = {
command_off_template: '0'
}
},
'volume_dimmer': {
type: 'light',
object_id: 'volume_dimmer',
discovery_payload: {
command_topic: true,
state_topic: false,
brightness_command_topic: true,
brightness_scale: 100,
brightness_state_topic: true,
brightness_value_template: '{{ value_json.value }}',
on_command_type: 'last',
payload_off: 0,
payload_on: 25
}
},

// Switch https://www.home-assistant.io/components/switch.mqtt
'switch': {
Expand Down
13 changes: 9 additions & 4 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,10 @@ Gateway.prototype.discoverValue = function (node, valueId) {
case 'sound_switch':
// https://github.com/OpenZWave/open-zwave/blob/master/config/Localization.xml#L1575
if (valueId.index === 2) { // volume control
cfg = copy(hassCfg.sound_switch)
cfg.discovery_payload.speed_state_topic = this.mqtt.getTopic(topic)
cfg.discovery_payload.speed_command_topic = cfg.discovery_payload.speed_state_topic + '/set'
cfg = copy(hassCfg.volume_dimmer)
cfg.discovery_payload.brightness_state_topic = this.mqtt.getTopic(topic)
cfg.discovery_payload.command_topic = cfg.discovery_payload.brightness_state_topic + '/set'
cfg.discovery_payload.brightness_command_topic = cfg.discovery_payload.command_topic
} else {
return
}
Expand Down Expand Up @@ -963,7 +964,11 @@ Gateway.prototype.discoverValue = function (node, valueId) {

payload = cfg.discovery_payload

if (!payload.hasOwnProperty('state_topic') || payload.state_topic === true) payload.state_topic = this.mqtt.getTopic(topic)
if (!payload.hasOwnProperty('state_topic') || payload.state_topic === true) {
payload.state_topic = this.mqtt.getTopic(topic)
} else if (payload.state_topic === false) {
delete payload.state_topic
}

if (payload.command_topic === true) payload.command_topic = this.mqtt.getTopic(topic, true)

Expand Down

0 comments on commit 3a08226

Please sign in to comment.