Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions web/bindings/homeassistant.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,21 @@
"availability_template: \"{{'online' if value_json.name == 'ready' else 'offline'}}\",",
"schema: 'template',",
"command_topic: `${ctx.vars.mqttTopic}/state/circuits/setState`,",
"state_topic: `${ctx.vars.mqttTopic}/state/circuits/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}`,",
"state_topic: `${ctx.vars.mqttTopic}/state/circuits/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/state`,",
"device: device_id,",
"command_on_template: `{\"id\": ${data.id}, \"isOn\": true}`,",
"effect_list: sys.circuits.getInterfaceById(data.id).getLightThemes().map(t => t.name),",
"command_on_template: `{\"id\": ${data.id}, \"isOn\": true{%if effect is defined%}, \"lightingTheme\": \"{{effect}}\"{%endif%}}`,",
"command_off_template: `{\"id\": ${data.id}, \"isOn\": false}`,",
"state_template: '{{value_json.isOn}}'});"
"state_template: '{{value_json.isOn}}',",
"effect_template: '{{value_json.lightingTheme.name}}'});"
],
"filter": "@bind=data.showInFeatures; === true && @bind=data.type.isLight; === true"
},
{
"topic": "@bind=vars.mqttTopic;/state/circuits/@bind=data.id;/@bind=data.name;/state",
"useRootTopic": false,
"message": "{\"id\":@bind=data.id;,\"isOn\":@bind=data.isOn?'\"on\"':'\"off\"';,\"lightingTheme\":@bind=data.lightingTheme;}",
"filter": "@bind=data.showInFeatures; === true && @bind=data.type.isLight; === true"
}
]
},
Expand Down
14 changes: 13 additions & 1 deletion web/interfaces/mqttInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,23 @@ export class MqttInterfaceBindings extends BaseInterfaceBindings {
logger.error(`Inbound MQTT ${topics} has an invalid id (${id}) in the message (${msg}).`)
};
let isOn = typeof msg.isOn !== 'undefined' ? utils.makeBool(msg.isOn) : typeof msg.state !== 'undefined' ? utils.makeBool(msg.state) : undefined;
var lightingTheme;
if (typeof msg.lightingTheme === 'string') {
logger.info("searching for light theme");
lightingTheme = sys.board.valueMaps.lightThemes.transformByName(msg.lightingTheme);
logger.info(`found light theme ${JSON.stringify(lightingTheme)}`);
if (typeof lightingTheme !== 'undefined') lightingTheme = lightingTheme.val;
}
switch (topics[topics.length - 2].toLowerCase()) {
case 'circuits':
case 'circuit': {
try {
if(typeof isOn !== 'undefined') await sys.board.circuits.setCircuitStateAsync(id, isOn);
if(typeof lightingTheme !== 'undefined') {
logger.info(`setting light theme of ${id} to ${lightingTheme}`)
await sys.board.circuits.setLightThemeAsync(id, lightingTheme);
} else if(typeof isOn !== 'undefined') {
await sys.board.circuits.setCircuitStateAsync(id, isOn);
}
}
catch (err) { logger.error(err); }
break;
Expand Down