Skip to content

Instantly share code, notes, and snippets.

@Koenkk
Last active June 1, 2023 08:40
Show Gist options
  • Save Koenkk/34e60391471f8a6333176594dd80445d to your computer and use it in GitHub Desktop.
Save Koenkk/34e60391471f8a6333176594dd80445d to your computer and use it in GitHub Desktop.
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 utils = require('zigbee-herdsman-converters/lib/utils');
const ota = require('zigbee-herdsman-converters/lib/ota');
const tuya = require('zigbee-herdsman-converters/lib/tuya');
const e = exposes.presets;
const ea = exposes.access;
const definition = {
fingerprint: tuya.fingerprint('TS0601', ['_TZE200_lsanae15', '_TZE200_bkkmqmyo', '_TZE200_eaac7dkw']),
model: 'TS0601_din_1',
vendor: 'TuYa',
description: 'Zigbee DIN energy meter',
fromZigbee: [tuya.fzDataPoints],
toZigbee: [tuya.tzDataPoints],
configure: tuya.configureMagicPacket,
exposes: [tuya.exposes.switch(), e.ac_frequency(), e.energy(), e.power(), e.power_factor(), e.voltage(), e.current(),
exposes.numeric('produced_energy', exposes.access.STATE).withUnit('kWh').withDescription('Sum of produced energy'),],
meta: {
tuyaDatapoints: [
[1, 'energy', tuya.valueConverter.divideBy100],
[6, null, tuya.valueConverter.phaseA], // voltage and current
[16, 'state', tuya.valueConverter.onOff],
[103, 'power', tuya.valueConverter.raw],
[105, 'ac_frequency', tuya.valueConverter.divideBy100],
[111, 'power_factor', tuya.valueConverter.divideBy10],
// Ignored for now; we don't know what the values mean
[109, null, null], // reactive_power in VArh, ignored for now
[101, null, null], // total active power (translated from chinese) - same as energy dp 1??
[102, 'produced_energy', tuya.valueConverter.divideBy100],
[9, null, null], // Fault - we don't know the possible values here
[110, null, null], // total reactive power (translated from chinese) - value is 0.03kvar, we already have kvarh on dp 109
[17, null, null], // Alarm set1 - value seems garbage "AAAAAAAAAAAAAABkAAEOAACqAAAAAAAKAAAAAAAA"
[18, null, null], // 18 - Alarm set2 - value seems garbage "AAUAZAAFAB4APAAAAAAAAAA="
],
},
whiteLabel: [{vendor: 'Hiking', model: 'DDS238-2'}, {vendor: 'TuYa', model: 'RC-MCB'}],
};
module.exports = definition;
@Koenkk
Copy link
Author

Koenkk commented Oct 11, 2022

Added it, please check with the updated external converter above. Make sure to update to z2m dev first (https://www.zigbee2mqtt.io/advanced/more/switch-to-dev-branch.html)

@ArGinTTT
Copy link

I'm not sure what do you mean to "check with the updated external converter"... I just uninstall and install again Edge in Home assistant,but for no nothing change...
Screenshot_20221011-180050

@gericho
Copy link

gericho commented Oct 11, 2022

updated it

/app/dist/util/externally-loaded.js:21
        exposes.numeric('produced_energy', access.STATE).withUnit('kWh').withDescription('Sum of produced energy'),],
                                           ^
ReferenceError: access is not defined
    at /app/dist/util/externally-loaded.js:21:44
    at Script.runInContext (node:vm:141:12)
    at Script.runInNewContext (node:vm:146:17)
    at Object.runInNewContext (node:vm:306:38)
    at loadModuleFromText (/app/lib/util/utils.ts:148:8)
    at loadModuleFromFile (/app/lib/util/utils.ts:155:12)
    at Object.getExternalConvertersDefinitions (/app/lib/util/utils.ts:165:25)
    at getExternalConvertersDefinitions.next (<anonymous>)
    at new ExternalConverters (/app/lib/extension/externalConverters.ts:12:20)
    at new Controller (/app/lib/controller.ts:84:58)

@Koenkk
Copy link
Author

Koenkk commented Oct 11, 2022

@ArGinTTT

external_converters:
  - ext_converter.js
  • start z2m, check if issue is fixed

@gericho I don't think you are using the latest dev (this was added yesterday I believe)

@gericho
Copy link

gericho commented Oct 11, 2022

@Koenkk just updated but I forget to update the repository, just a moment

@gericho
Copy link

gericho commented Oct 11, 2022

updated

[17:15:54] INFO: Preparing to start...
[17:15:57] INFO: Socat not enabled
[17:16:02] INFO: Starting Zigbee2MQTT...
/app/dist/util/externally-loaded.js:21
        exposes.numeric('produced_energy', access.STATE).withUnit('kWh').withDescription('Sum of produced energy'),],
                                           ^
ReferenceError: access is not defined
    at /app/dist/util/externally-loaded.js:21:44
    at Script.runInContext (node:vm:141:12)
    at Script.runInNewContext (node:vm:146:17)
    at Object.runInNewContext (node:vm:306:38)
    at loadModuleFromText (/app/lib/util/utils.ts:148:8)
    at loadModuleFromFile (/app/lib/util/utils.ts:155:12)
    at Object.getExternalConvertersDefinitions (/app/lib/util/utils.ts:165:25)
    at getExternalConvertersDefinitions.next (<anonymous>)
    at new ExternalConverters (/app/lib/extension/externalConverters.ts:12:20)
    at new Controller (/app/lib/controller.ts:84:58)

@Koenkk
Copy link
Author

Koenkk commented Oct 11, 2022

@gericho fixed

@gericho
Copy link

gericho commented Oct 11, 2022

Unfortunately I don't have proper scenario to test it completely (need to wait @ArGinTTT for solar panels production) but seems to work. Thank you again @Koenkk !!

Immagine 2022-10-11 173134

@ArGinTTT
Copy link

Hi,

I managed to integrate also the converter...it looks like it's working...
i will share a more relevant feedback by end of tomorrow.

Thank you very much!

Screenshot_20221011-193425-845

@gericho
Copy link

gericho commented Oct 11, 2022

@Koenkk seems webui icon was lost in the process.

@Koenkk
Copy link
Author

Koenkk commented Oct 11, 2022

@gericho I believe there is no icon for produced_energy, it has t be added to the frontend later.

@gericho
Copy link

gericho commented Oct 11, 2022

Sorry @Koenkk I meant device icon. Same picture device as the old tuya meter. Thank you.

@Koenkk
Copy link
Author

Koenkk commented Oct 11, 2022

The device picture will be added with the next release.

@ArGinTTT
Copy link

Hello together,

I just checked the device with the new settings, and looks to work ok.
Anyway in case that someone have some questions about how it works, below you can see a picture:
image

Thank you again for all your support!

@gericho
Copy link

gericho commented Oct 12, 2022

Thank you for your detailed clarification, this relatively cheap power meter, I mean the IVAP version, have wonderful potentials (looking forward to have a solar system as soon as possible too.... for obvious reasons....)

@Koenkk
Copy link
Author

Koenkk commented Oct 12, 2022

Great, integrated the changes.

@Matriciel
Copy link

Matriciel commented Oct 14, 2022

Hi,
I have two differents models: _TZE200_bkkmqmyo and _TZE200_lsanae15.
With this converter, the first work correctly, i have voltage, power, current, frequency and power factor, but, with the second, only voltage and current.
Power, power factor and freqquency are not working.
I think that this model was a bit different that first model.
Have you tested it and, i need dev branch for using it ?
I am with 1.28.0 stable

Edit:
Info is sent every 2 minutes (for the _TZE200_lsanae15 model) and every minute for the _TZE200_bkkmqmyo model.
Is there a possibility to modify this timer to have a return every 30 seconds, as on the original model?

@Koenkk
Copy link
Author

Koenkk commented Oct 18, 2022

@Matriciel AFAIK there is no way to change the reporting interval of TuYa devices.

@Matriciel
Copy link

@Koenkk thank for your response. For other point, i need to wait net release for all exposes point with _TZE200_lsanae15 ?

@gericho
Copy link

gericho commented Oct 18, 2022

Is there a possibility to modify this timer to have a return every 30 seconds, as on the original model?

please be aware my comment can be off topic

I am on the same boat, Home asisstant DB is growing so fast with 3 tuya power-meters, querying the DB shows a consistent flooding so at the moment I excluded some entities related to this Power meter. I'm searching if there is an HA recorder setting to get less granularity only on some entities, still no luck. Maybe someone can help.

@kirillec
Copy link

@gericho, Use the addon MariaDB there everything is done very simply
Here are all the details:

https://www.home-assistant.io/integrations/recorder/

@gericho
Copy link

gericho commented Oct 19, 2022

Use the addon MariaDB there everything is done very simply

Thank you for the advice, I tiried already days ago, I'm on a raspberry Pi3, Maria DB literally killed the system on a 64bit Hassio, I downgraded yesterday to 32bit Hassio using a full backup, I'll try if works better. BTW 32bit on this machine is WAY faster, 30% ram saved, never used swap, the system is fresh like new again. I'll try mariaDB on 32bit, but I'm worried SD cards (I'm using a sandisk max endurance) are no longer a viable solution with latest Hassio releases, I see all people switching to SSD, at that point better to point on a faster machine. I STILL think Home assistant developers have to take in consideration to customize granularity in recorder by entity. A sensor that pushes 10+ entities to the network (if you use original hub and app) every 10 seconds, is just sad, starting from TuYa decision to flood the network in general, no doubt.

@Koenkk
Copy link
Author

Koenkk commented Oct 19, 2022

@raslr6
Copy link

raslr6 commented Oct 19, 2022

Hi, thanks for your great job, but i have a error with the code.

[18:09:33] INFO: Preparing to start...
[18:09:33] INFO: Socat not enabled
[18:09:34] INFO: Starting Zigbee2MQTT...
/app/dist/util/externally-loaded.js:20
exposes: [tuya.exposes.switch(), e.ac_frequency(), e.energy(), e.power(), e.power_factor(), e.voltage(), e.current(),
^
TypeError: tuya.exposes.switch is not a function
at /app/dist/util/externally-loaded.js:20:34
at Script.runInContext (node:vm:139:12)
at Script.runInNewContext (node:vm:144:17)
at Object.runInNewContext (node:vm:298:38)
at loadModuleFromText (/app/lib/util/utils.ts:148:8)
at loadModuleFromFile (/app/lib/util/utils.ts:155:12)
at Object.getExternalConvertersDefinitions (/app/lib/util/utils.ts:165:25)
at getExternalConvertersDefinitions.next ()
at new ExternalConverters (/app/lib/extension/externalConverters.ts:12:20)
at new Controller (/app/lib/controller.ts:84:58)

what can i do?
thanks

@Koenkk
Copy link
Author

Koenkk commented Oct 20, 2022

@raslr6
Copy link

raslr6 commented Oct 20, 2022

@Koenkk How can I look at it and if I don't have it, how is it updated, I don't have much skill even with all this, i have home assistant add-on thanks

@raslr6
Copy link

raslr6 commented Oct 20, 2022

@Koenkk I'm sorry, I didn't notice that edge was another version, it's already working, thank you very much

@Koenkk
Copy link
Author

Koenkk commented Oct 20, 2022

To be sure you are on the latest edge, uninstall and install the addon

@ArGinTTT
Copy link

Hello gentlemans,

Long time din't hear us. I hope you are doing fine.
I think I need your support again :| Apparently I buyed a second DDS238-2 zigbee, but apparently it's a different manufacture: TZE200_byzdayie, and again I can't see in zigbee2mqtt "produced energy" like in manufacture TZE200_bkkmqmyo. Can you give me some hints how to do it also for this device? It will be nice if I would get the same parameters for both of them, like in attached picture.

Thank you!

image

@ArGinTTT
Copy link

ArGinTTT commented Jun 1, 2023

Hi,
I also observed that in TZE200_byzdayie the power is not give negative values, like power from TZE200_bkkmqmyo. Ca you please support me?
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment