Skip to content

Commit

Permalink
Add HASS bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
tagyoureit committed Jul 11, 2022
1 parent cbb5ec0 commit 7f9a343
Show file tree
Hide file tree
Showing 2 changed files with 263 additions and 1 deletion.
23 changes: 22 additions & 1 deletion defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
"tempPrecision": 2,
"tempUnits": "@bind=sys.board.valueMaps.tempUnits.getName(state.temps.units);"
}

},
"mqttAlt": {
"name": "MQTTAlt",
Expand All @@ -201,6 +200,28 @@
"changesOnly": true
}
},
"homeAssistant": {
"name": "Home Assistant",
"type": "mqtt",
"enabled": false,
"fileName": "homeassistant.json",
"globals": {},
"options": {
"protocol": "mqtt://",
"host": "192.168.0.1",
"port": 1883,
"username": "",
"password": "",
"selfSignedCertificate": false,
"retain": true,
"qos": 0,
"changesOnly": true
},
"vars": {
"hassTopic": "homeassistant",
"mqttTopic": "@bind=(state.equipment.model).replace(' ','-').replace('/','').toLowerCase();Alt"
}
},
"rem": {
"name": "Relay Equipment Manager",
"type": "rem",
Expand Down
241 changes: 241 additions & 0 deletions web/bindings/homeassistant.json
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}}'});"
]
}
]
}

]
}

0 comments on commit 7f9a343

Please sign in to comment.