-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Amina S device #8191
Merged
Merged
Added Amina S device #8191
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b0987c5
Added Amina S device
somlioy 9b9b3a0
Cleanup and converted most exposes to extend
somlioy 99fdbdd
Removed unnecessary binds
somlioy c96eada
Binary values to lowercase
somlioy 7316028
Lint-Fix, removed simulation variables
somlioy 7b4282d
Added polling of energy attributes in onEvent
somlioy 70d6577
Fixed typo
somlioy 8263316
Implemented e.list() on alarms
somlioy f23e32b
Removed 'no_alarm' from alarms-enum
somlioy edffc5e
Create alarms array using .filter instead
somlioy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,355 @@ | ||
import {Zcl} from 'zigbee-herdsman'; | ||
|
||
import fz from '../converters/fromZigbee'; | ||
import * as exposes from '../lib/exposes'; | ||
import {binary, deviceAddCustomCluster, electricityMeter, numeric, onOff} from '../lib/modernExtend'; | ||
import * as ota from '../lib/ota'; | ||
import * as reporting from '../lib/reporting'; | ||
import {DefinitionWithExtend, Fz, KeyValue, Tz} from '../lib/types'; | ||
import * as utils from '../lib/utils'; | ||
|
||
const e = exposes.presets; | ||
const ea = exposes.access; | ||
|
||
const manufacturerOptions = {manufacturerCode: 0x143b}; | ||
|
||
const aminaControlAttributes = { | ||
cluster: 0xfee7, | ||
alarms: 0x02, | ||
ev_status: 0x03, | ||
connect_status: 0x04, | ||
single_phase: 0x05, | ||
offline_current: 0x06, | ||
offline_single_phase: 0x07, | ||
time_to_offline: 0x08, | ||
enable_offline: 0x09, | ||
total_active_energy: 0x10, | ||
last_session_energy: 0x11, | ||
}; | ||
|
||
const aminaAlarms = [ | ||
'Welded relay(s)', | ||
'Wrong voltage balance', | ||
'RDC-DD DC Leakage', | ||
'RDC-DD AC Leakage', | ||
'High Temperature', | ||
'Overvoltage', | ||
'Overcurrent', | ||
'Car communication error', | ||
'Charger processing error', | ||
'Critical overcurrent', | ||
'Critical powerloss', | ||
]; | ||
|
||
const fzLocal = { | ||
charge_limit: { | ||
cluster: 'genLevelCtrl', | ||
type: ['attributeReport', 'readResponse'], | ||
convert: (model, msg, publish, options, meta) => { | ||
const result: KeyValue = {}; | ||
|
||
if (msg.data.currentLevel !== undefined) { | ||
result.charge_limit = msg.data['currentLevel']; | ||
} | ||
|
||
return result; | ||
}, | ||
} satisfies Fz.Converter, | ||
|
||
ev_status: { | ||
cluster: 'aminaControlCluster', | ||
type: ['attributeReport', 'readResponse'], | ||
convert: (model, msg, publish, options, meta) => { | ||
const result: KeyValue = {}; | ||
|
||
if (msg.data.evStatus !== undefined) { | ||
let statusText = ''; | ||
const evStatus = msg.data['evStatus']; | ||
|
||
result.ev_connected = (evStatus & (1 << 0)) !== 0; | ||
if (result.ev_connected) { | ||
statusText = 'EV Connected'; | ||
} else { | ||
statusText = 'Not Connected'; | ||
} | ||
if ((evStatus & (1 << 1)) !== 0) statusText = 'Ready to charge'; | ||
if ((evStatus & (1 << 2)) !== 0) statusText = 'Charging'; | ||
if ((evStatus & (1 << 3)) !== 0) statusText = 'Charging Paused'; | ||
|
||
result.derated = (evStatus & (1 << 15)) !== 0; | ||
if (result.derated) statusText += ', Derated'; | ||
|
||
result.ev_status = statusText; | ||
|
||
return result; | ||
} | ||
}, | ||
} satisfies Fz.Converter, | ||
|
||
alarms: { | ||
cluster: 'aminaControlCluster', | ||
type: ['attributeReport', 'readResponse'], | ||
convert: (model, msg, publish, options, meta) => { | ||
const result: KeyValue = {}; | ||
|
||
if (msg.data.alarms !== undefined) { | ||
result.alarms = []; | ||
result.alarm_active = false; | ||
|
||
for (let i = 0; i < 16; i++) { | ||
if ((msg.data['alarms'] >> i) & 0x01) { | ||
let alarm = aminaAlarms[i]; | ||
if (alarm === undefined) { | ||
alarm = `Unknown Alarm bit #${i}`; | ||
} | ||
|
||
(result.alarms as string[]).push(alarm); | ||
result.alarm_active = true; | ||
} | ||
} | ||
|
||
if (result.alarm_active === false) { | ||
result.alarms = 'No Alarm'; | ||
} | ||
|
||
return result; | ||
} | ||
}, | ||
} satisfies Fz.Converter, | ||
}; | ||
|
||
const tzLocal = { | ||
charge_limit: { | ||
key: ['charge_limit'], | ||
convertSet: async (entity, key, value, meta) => { | ||
const payload = {level: value, transtime: 0}; | ||
await entity.command('genLevelCtrl', 'moveToLevel', payload, utils.getOptions(meta.mapped, entity)); | ||
}, | ||
|
||
convertGet: async (entity, key, meta) => { | ||
await entity.read('genLevelCtrl', ['currentLevel'], manufacturerOptions); | ||
}, | ||
} satisfies Tz.Converter, | ||
|
||
ev_status: { | ||
key: ['ev_status'], | ||
convertGet: async (entity, key, meta) => { | ||
await entity.read('aminaControlCluster', ['evStatus'], manufacturerOptions); | ||
}, | ||
} satisfies Tz.Converter, | ||
|
||
alarms: { | ||
key: ['alarms'], | ||
convertGet: async (entity, key, meta) => { | ||
await entity.read('aminaControlCluster', ['alarms'], manufacturerOptions); | ||
}, | ||
} satisfies Tz.Converter, | ||
|
||
total_active_power: { | ||
key: ['total_active_power'], | ||
convertGet: async (entity, key, meta) => { | ||
await entity.read('haElectricalMeasurement', ['totalActivePower'], manufacturerOptions); | ||
}, | ||
} satisfies Tz.Converter, | ||
}; | ||
|
||
const definitions: DefinitionWithExtend[] = [ | ||
{ | ||
zigbeeModel: ['amina S'], | ||
model: 'amina S', | ||
vendor: 'Amina Distribution AS', | ||
description: 'Amina S EV Charger', | ||
ota: ota.zigbeeOTA, | ||
fromZigbee: [fzLocal.charge_limit, fzLocal.ev_status, fzLocal.alarms, fz.electrical_measurement], | ||
Koenkk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
toZigbee: [tzLocal.charge_limit, tzLocal.ev_status, tzLocal.alarms, tzLocal.total_active_power], | ||
exposes: [ | ||
e | ||
.numeric('charge_limit', ea.ALL) | ||
.withUnit('A') | ||
.withValueMin(6) | ||
.withValueMax(32) | ||
.withValueStep(1) | ||
.withDescription('Maximum allowed amperage draw'), | ||
e.text('ev_status', ea.STATE_GET).withDescription('Current charging status'), | ||
e.binary('ev_connected', ea.STATE, 'true', 'false').withDescription('An EV is connected to the charger'), | ||
e.binary('derated', ea.STATE, 'true', 'false').withDescription('Charging derated due to high temperature'), | ||
e.text('alarms', ea.STATE_GET).withDescription('Alarms reported by EV Charger'), | ||
e.binary('alarm_active', ea.STATE, 'true', 'false').withDescription('An active alarm is present'), | ||
], | ||
|
||
extend: [ | ||
electricityMeter({ | ||
cluster: 'electrical', | ||
acFrequency: true, | ||
threePhase: true, | ||
}), | ||
|
||
deviceAddCustomCluster('aminaControlCluster', { | ||
ID: aminaControlAttributes.cluster, | ||
manufacturerCode: manufacturerOptions.manufacturerCode, | ||
attributes: { | ||
alarms: {ID: aminaControlAttributes.alarms, type: Zcl.DataType.BITMAP16}, | ||
evStatus: {ID: aminaControlAttributes.ev_status, type: Zcl.DataType.BITMAP16}, | ||
connectStatus: {ID: aminaControlAttributes.connect_status, type: Zcl.DataType.BITMAP16}, | ||
singlePhase: {ID: aminaControlAttributes.single_phase, type: Zcl.DataType.UINT8}, | ||
offlineCurrent: {ID: aminaControlAttributes.offline_current, type: Zcl.DataType.UINT8}, | ||
offlineSinglePhase: {ID: aminaControlAttributes.offline_single_phase, type: Zcl.DataType.UINT8}, | ||
timeToOffline: {ID: aminaControlAttributes.time_to_offline, type: Zcl.DataType.UINT16}, | ||
enableOffline: {ID: aminaControlAttributes.enable_offline, type: Zcl.DataType.UINT8}, | ||
totalActiveEnergy: {ID: aminaControlAttributes.total_active_energy, type: Zcl.DataType.UINT32}, | ||
lastSessionEnergy: {ID: aminaControlAttributes.last_session_energy, type: Zcl.DataType.UINT32}, | ||
}, | ||
commands: {}, | ||
commandsResponse: {}, | ||
}), | ||
|
||
onOff({ | ||
powerOnBehavior: false, | ||
}), | ||
|
||
numeric({ | ||
name: 'total_active_power', | ||
cluster: 'haElectricalMeasurement', | ||
attribute: 'totalActivePower', | ||
description: 'Instantaneous measured total active power', | ||
reporting: {min: '10_SECONDS', max: 'MAX', change: 5}, | ||
unit: 'kW', | ||
scale: 1000, | ||
precision: 2, | ||
access: 'STATE_GET', | ||
}), | ||
|
||
numeric({ | ||
name: 'total_active_energy', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'totalActiveEnergy', | ||
description: 'Sum of consumed energy', | ||
//reporting: {min: '10_SECONDS', max: 'MAX', change: 5}, // Not Reportable atm | ||
unit: 'kWh', | ||
scale: 1000, | ||
precision: 2, | ||
access: 'STATE_GET', | ||
}), | ||
|
||
numeric({ | ||
name: 'last_session_energy', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'lastSessionEnergy', | ||
description: 'Sum of consumed energy last session', | ||
//reporting: {min: '10_SECONDS', max: 'MAX', change: 5}, // Not Reportable atm | ||
unit: 'kWh', | ||
scale: 1000, | ||
precision: 2, | ||
access: 'STATE_GET', | ||
}), | ||
|
||
binary({ | ||
name: 'single_phase', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'singlePhase', | ||
description: 'Enable single phase charging. A restart of charging is required for the change to take effect.', | ||
valueOn: ['Enable', 1], | ||
valueOff: ['Disable', 0], | ||
entityCategory: 'config', | ||
}), | ||
|
||
binary({ | ||
name: 'enable_offline', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'enableOffline', | ||
description: 'Enable offline mode when connection to the network is lost', | ||
valueOn: ['Enable', 1], | ||
valueOff: ['Disable', 0], | ||
entityCategory: 'config', | ||
}), | ||
|
||
numeric({ | ||
name: 'time_to_offline', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'timeToOffline', | ||
description: 'Time until charger will behave as offline after connection has been lost', | ||
valueMin: 0, | ||
valueMax: 60, | ||
valueStep: 1, | ||
unit: 's', | ||
entityCategory: 'config', | ||
}), | ||
|
||
numeric({ | ||
name: 'offline_current', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'offlineCurrent', | ||
description: 'Maximum allowed amperage draw when device is offline', | ||
valueMin: 6, | ||
valueMax: 32, | ||
valueStep: 1, | ||
unit: 'A', | ||
entityCategory: 'config', | ||
}), | ||
|
||
binary({ | ||
name: 'offline_single_phase', | ||
cluster: 'aminaControlCluster', | ||
attribute: 'offlineSinglePhase', | ||
description: 'Use single phase charging when device is offline', | ||
valueOn: ['Enable', 1], | ||
valueOff: ['Disable', 0], | ||
entityCategory: 'config', | ||
}), | ||
], | ||
|
||
endpoint: (device) => { | ||
return {default: 10}; | ||
}, | ||
|
||
configure: async (device, coordinatorEndpoint) => { | ||
const endpoint = device.getEndpoint(10); | ||
|
||
const binds = ['genBasic', 'genOnOff', 'haElectricalMeasurement', 'genLevelCtrl', 'aminaControlCluster']; | ||
somlioy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await reporting.bind(endpoint, coordinatorEndpoint, binds); | ||
|
||
await endpoint.configureReporting('genLevelCtrl', [ | ||
{ | ||
attribute: 'currentLevel', | ||
minimumReportInterval: 10, | ||
maximumReportInterval: 65000, | ||
reportableChange: 1, | ||
}, | ||
]); | ||
|
||
await endpoint.configureReporting('aminaControlCluster', [ | ||
{ | ||
attribute: 'evStatus', | ||
minimumReportInterval: 10, | ||
maximumReportInterval: 65000, | ||
reportableChange: 1, | ||
}, | ||
]); | ||
|
||
await endpoint.configureReporting('aminaControlCluster', [ | ||
{ | ||
attribute: 'alarms', | ||
minimumReportInterval: 10, | ||
maximumReportInterval: 65000, | ||
reportableChange: 1, | ||
}, | ||
]); | ||
|
||
await endpoint.read('aminaControlCluster', [ | ||
'alarms', | ||
'evStatus', | ||
'connectStatus', | ||
'singlePhase', | ||
'offlineCurrent', | ||
'offlineSinglePhase', | ||
'timeToOffline', | ||
'enableOffline', | ||
'totalActiveEnergy', | ||
'lastSessionEnergy', | ||
]); | ||
}, | ||
}, | ||
]; | ||
|
||
export default definitions; | ||
module.exports = definitions; |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make all of these
snake_case
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, what is the purpose of converting those to snake case but not status texts for ev_status for instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually text is free format, but for this use case it may be better to use a
e.enum()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably enum would work, but as the value from the device is «bit encoded» one could in theory have multiple alarms as once? Probably not very likely tho, but possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point,
e.list()
with ane.enum()
as the type would be the best then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have any examples of how to do this, because whatever I do, the GUI only shows an array of strings, or is this expected behaviour?
I defined:
In the fzLocal.alarms converter:
And finally the expose:
Example result with bit 1, 3 and 12 enabled:

Example result with no alarms:

I would perhaps expect something like this, not editable of course:

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is expected indeed, the frontend should be improved a bit here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright then, this is implemented in 8263316