-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbb5ec0
commit 7f9a343
Showing
2 changed files
with
263 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
{ | ||
"context": { | ||
"name": "Home Assistant", | ||
"type": "mqtt", | ||
"options": { | ||
"formatter": [ | ||
{ | ||
"transform": ".toLowerCase()" | ||
}, | ||
{ | ||
"regexkey": "\\s", | ||
"replace": "", | ||
"description": "Remove whitespace" | ||
}, | ||
{ | ||
"regexkey": "\\/", | ||
"replace": "", | ||
"description": "Remove /" | ||
}, | ||
{ | ||
"regexkey": "\\+", | ||
"replace": "", | ||
"description": "Remove +" | ||
}, | ||
{ | ||
"regexkey": "\\$", | ||
"replace": "", | ||
"description": "Remove $" | ||
}, | ||
{ | ||
"regexkey": "\\#", | ||
"replace": "", | ||
"description": "Remove #" | ||
} | ||
], | ||
"rootTopic-DIRECTIONS": "rootTopic in config.json is ingored. Instead set the two topic variables in the vars section", | ||
"_rootTopic": "@bind=(state.equipment.model).replace(' ','-').replace(' / ','').toLowerCase();", | ||
"clientId": "@bind=`hass_njsPC_${webApp.mac().replace(/:/g, '_'}-${webApp.httpPort()}`;" | ||
} | ||
}, | ||
"events": [ | ||
{ | ||
"name": "circuit", | ||
"description": "Populate the circuits topics", | ||
"topics": [ | ||
{ | ||
"topic": "@bind=vars.hassTopic;/switch/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name: 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"let icontype='mdi:toggle-switch-variant';", | ||
"if (data.type.val==1) {icontype='mdi:hot-tub'};", | ||
"if (data.type.val==2) {icontype='mdi:pool'};", | ||
"return JSON.stringify({ name: data.name,", | ||
"unique_id: `poolController-${data.id}-${data.name.replace(/\\s+/g, '').toLowerCase()}`,", | ||
"state_topic: `${ctx.vars.mqttTopic}/state/circuits/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}`,", | ||
"command_topic: `${ctx.vars.mqttTopic}/state/circuits/setState`,", | ||
"payload_on: `{\"id\": ${data.id}, \"isOn\": true}`,", | ||
"payload_off: `{\"id\": ${data.id}, \"isOn\": false}`,", | ||
"state_on: `on`,", | ||
"state_off: `off`,", | ||
"device: device_id,", | ||
"device_class: 'switch',", | ||
"icon: icontype,", | ||
"value_template:'{{value_json.isOn}}'});" | ||
], | ||
"filter": "@bind=data.showInFeatures; === true && @bind=data.type.isLight; !== true" | ||
}, | ||
{ | ||
"topic": "@bind=vars.hassTopic;/light/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: `Pool ${data.name}`,", | ||
"unique_id: `poolController-${data.id}-pool${data.name.replace(/\\s+/g, '').toLowerCase()}`,", | ||
"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()}`,", | ||
"device: device_id,", | ||
"command_on_template: `{\"id\": ${data.id}, \"isOn\": true}`,", | ||
"command_off_template: `{\"id\": ${data.id}, \"isOn\": false}`,", | ||
"state_template: '{{value_json.isOn}}'});" | ||
], | ||
"filter": "@bind=data.showInFeatures; === true && @bind=data.type.isLight; === true" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "pump", | ||
"description": "Populate the pumps topics", | ||
"topics": [ | ||
{ | ||
"topic": "@bind=vars.hassTopic;/sensor/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;-rpm/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: `${data.name} RPM`,", | ||
"unique_id: `poolController-${data.id}-${data.name.replace(/\\s+/g, '').toLowerCase()}-rpm`,", | ||
"state_topic: `${ctx.vars.mqttTopic}/state/pumps/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/rpm`,", | ||
"device: device_id,", | ||
"icon: 'mdi:pump',", | ||
"unit_of_measurement: 'rpm',", | ||
"value_template:'{{value_json.rpm}}'});" | ||
] | ||
}, | ||
{ | ||
"topic": "@bind=vars.hassTopic;/sensor/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;-watts/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: `${data.name} watts`,", | ||
"unique_id: `poolController-${data.id}-${data.name.replace(/\\s+/g, '').toLowerCase()}-watts`,", | ||
"state_topic: `${ctx.vars.mqttTopic}/state/pumps/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/watts`,", | ||
"device: device_id,", | ||
"icon: 'mdi:lightning-bolt',", | ||
"unit_of_measurement: 'W',", | ||
"state_class: 'measurement',", | ||
"device_class: 'power',", | ||
"value_template:'{{value_json.watts}}'});" | ||
] | ||
}, | ||
{ | ||
"topic": "@bind=vars.hassTopic;/sensor/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;-flow/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: `${data.name} flow`,", | ||
"unique_id: `poolController-${data.id}-${data.name.replace(/\\s+/g, '').toLowerCase()}-flow`,", | ||
"state_topic: `${ctx.vars.mqttTopic}/state/pumps/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/flow`,", | ||
"device: device_id,", | ||
"icon: 'mdi:waves-arrow-right',", | ||
"unit_of_measurement: 'gpm',", | ||
"value_template:'{{value_json.flow}}'});" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "feature", | ||
"description": "Populate the feature topics", | ||
"topics": [ | ||
{ | ||
"topic": "@bind=vars.hassTopic;/switch/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: data.name,", | ||
"unique_id: `poolController-${data.id}-${data.name.replace(/\\s+/g, '').toLowerCase()}`,", | ||
"state_topic: `${ctx.vars.mqttTopic}/state/features/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}`,", | ||
"command_topic: `${ctx.vars.mqttTopic}/state/features/setState`,", | ||
"payload_on: `{\"id\": ${data.id}, \"isOn\": true}`,", | ||
"payload_off: `{\"id\": ${data.id}, \"isOn\": false}`,", | ||
"state_on: `on`,", | ||
"state_off: `off`,", | ||
"device: device_id,", | ||
"device_class: 'switch',", | ||
"value_template:'{{value_json.isOn}}'});" | ||
], | ||
"filter": "@bind=data.showInFeatures; === true" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "body", | ||
"description": "Populate the pool body/heater topics", | ||
"topics": [ | ||
{ | ||
"topic": "@bind=vars.hassTopic;/climate/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-@bind=data.id;-@bind=data.name;/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: `${data.name} Heater`,", | ||
"unique_id: `poolController-body-${data.id}-${data.name.replace(/\\s+/g, '').toLowerCase()}`,", | ||
"action_topic: `${ctx.vars.mqttTopic}/state/temps/bodies/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/heatStatus`,", | ||
"action_template: `{{ 'off' if value_json.heatStatus.val==0 else 'heating' }}`,", | ||
"device: device_id,", | ||
"modes: ['off', 'heat'],", | ||
"mode_command_template: `{\"id\": ${data.id}, \"mode\": {{0 if value=='off' else 1}}}`,", | ||
"mode_command_topic: `${ctx.vars.mqttTopic}/state/body/heatmode`,", | ||
"mode_state_template: `{{ 'off' if value_json.heatMode.val==0 else 'heat' }}`,", | ||
"mode_state_topic: `${ctx.vars.mqttTopic}/state/temps/bodies/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/heatMode`,", | ||
"max_temp: `${(state.temps.data.units.name === 'F') ? 104.0 : 40.0}`,", | ||
"min_temp: `${(state.temps.data.units.name === 'F') ? 65.0 : 18.0}`,", | ||
"temperature_command_template: `{\"id\": ${data.id}, \"setPoint\": {{value}}}`,", | ||
"temperature_command_topic: `${ctx.vars.mqttTopic}/state/body/setpoint`,", | ||
"temperature_state_template: '{{value_json.setPoint}}',", | ||
"temperature_state_topic: `${ctx.vars.mqttTopic}/state/temps/bodies/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/setPoint`,", | ||
"temperature_unit: `${state.temps.data.units.name}`,", | ||
"current_temperature_topic: `${ctx.vars.mqttTopic}/state/temps/bodies/${data.id}/${data.name.replace(/\\s+/g, '').toLowerCase()}/temp`,", | ||
"current_temperature_template: '{{value_json.temp}}'});" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "temps", | ||
"description": "Populate the temp sensor", | ||
"topics": [ | ||
{ | ||
"topic": "@bind=vars.hassTopic;/sensor/@bind=vars.mqttTopic;/@bind=vars.mqttTopic;-1-airsensor/config", | ||
"useRootTopic": false, | ||
"processor": [ | ||
"let device_id = {", | ||
" name : 'Pool Controller - njsPC',", | ||
" ids: [`${ctx.vars.mqttTopic}`],", | ||
" suggested_area : 'Pool'};", | ||
"return JSON.stringify({ name: `Air temp`,", | ||
"unique_id: `poolController-1-airsensor`,", | ||
"device: device_id,", | ||
"device_class: 'temperature',", | ||
"state_topic: `${ctx.vars.mqttTopic}/state/temps/air`,", | ||
"unit_of_measurement: `°${state.temps.data.units.name}`,", | ||
"value_template: '{{value_json.temp}}'});" | ||
] | ||
} | ||
] | ||
} | ||
|
||
] | ||
} |