Skip to content
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

Custom device with two endpoints #3432

Closed
tomasz-grobelny opened this issue Nov 29, 2021 · 4 comments
Closed

Custom device with two endpoints #3432

tomasz-grobelny opened this issue Nov 29, 2021 · 4 comments
Labels

Comments

@tomasz-grobelny
Copy link

tomasz-grobelny commented Nov 29, 2021

I am trying to make my own device based on ptvo.info, Z1 Mini, Arduino and connect it to Home Assistant using Z2M. I created an external converter that is half working and need help with the other part. The part that works is the part concerned with reading - whenever my device changes state, arduino sends packet through UART, Z1 Mini sends that over zigbee to z2m and HA presents it nicely as device with two lights ('salon' and 'kuchnia'). Here is how it looks like:

const fz = require('zigbee-herdsman-converters/converters/fromZigbee');
const tz = require('zigbee-herdsman-converters/converters/toZigbee');
const exposes = require('zigbee-herdsman-converters/lib/exposes');
const reporting = require('zigbee-herdsman-converters/lib/reporting');
const extend = require('zigbee-herdsman-converters/lib/extend');
const e = exposes.presets;
const ea = exposes.access;

var localFz = {
        cluster: 'genMultistateValue',
        type: ['attributeReport', 'readResponse'],
        convert: (model, msg, publish, options, meta) => {
            console.log('convert');
            let data = msg.data['stateText'];
            var result = {};
            if(data[1]==97)
                result.state_kuchnia = 'OFF';
            if(data[1]==65)
                result.state_kuchnia = 'ON';
            if(data[2]==97)
                result.state_salon = 'OFF';
            if(data[2]==65)
                result.state_salon = 'ON';
            return result;
        },
    };


var localTz={
    key: ['state'],
    convertSet: async (entity, key, value, meta) => {
        console.log('convertSet');
    },
};

const definition = {
    zigbeeModel: ['diylr.lights'],
    model: 'LR Lights',
    vendor: 'DIY',
    description: 'Living room custom light switch',
    fromZigbee: [localFz],
    toZigbee: [localTz],
    exposes: [exposes.light().withEndpoint('kuchnia'), exposes.light().withEndpoint('salon')],
    meta: {multiEndpoint: true},
    endpoint: (device) => { return {'kuchnia': 1, 'salon': 2}; },
};

module.exports = definition;

However, when trying to turn on/off/toggle the light in HA it says "Entity '0x122137861872/kuchnia' is unknown". Log says:

Zigbee2MQTT:debug 2021-11-29 16:28:53: Received MQTT message on 'zigbee2mqtt/0x122137861872/kuchnia/set' with data '{"state_kuchnia":"ON"}'
Zigbee2MQTT:info  2021-11-29 16:28:53: MQTT publish: topic 'zigbee2mqtt/bridge/log', payload '{"message":{"friendly_name":"0x122137861872/kuchnia"},"type":"entity_not_found"}'
Zigbee2MQTT:error 2021-11-29 16:28:53: Entity '0x122137861872/kuchnia' is unknown

How do I actually convince HA/Z2M to do something when I try to switch the light on in HA UI? What I don't like with the log message is that endpoint name is twice (topic name + payload json), but don't know how to fix. My bet would be that exposes definition needs some tweaking so that HA sends to 'zigbee2mqtt/0x122137861872/set' and not 'zigbee2mqtt/0x122137861872/kuchnia/set' - but don't know how to have that.

@Koenkk
Copy link
Owner

Koenkk commented Nov 29, 2021

@tomasz-grobelny
Copy link
Author

You can only use endpoint names listed in https://github.com/Koenkk/zigbee2mqtt/blob/df0543d4b7d04578c5000a889090259d3abcb32f/lib/util/utils.ts#L30

Works, thanks a lot!

Is there any reason why endpoint names cannot be any text? And even if it absolutely needs to be limited to this set maybe there should be a (more visible?) warning?

@Koenkk
Copy link
Owner

Koenkk commented Nov 30, 2021

Is there any reason why endpoint names cannot be any text?

Because these endpoint names cannot be used in the friendly name, e.g. a friendly_name of kitchen_plug/left is not
allowed.

And even if it absolutely needs to be limited to this set maybe there should be a (more visible?) warning?

Agree, would you mind implementing such check?

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants