本帖最后由 polisher 于 2024-1-5 11:44 编辑
PTVO是一款免代码的ZIGBEE固件生成器,通过撘积木的方式快速DIY一些基于ZIGBEE小玩意儿,特别适合我等小白们。这里要感谢 @冬瓜HA 大神发布和正在连载的PTVO教程系列。点击这里膜拜大神的帖子
用PTVO只需要了解一些硬件知识即可上手,本人菜鸟一枚,下面以Zigbee墙壁插座作为实例抛砖引玉,望不吝赐教。
一、电路图
二、PTVO设置
三、设置简述
1.指示灯
电路图上,我们在LED发光二极管正极接入3.3V(R2电阻限流),负极接在CC2350的GPIO20引脚上,也就是说只要该引脚为低电平时LED工作。于是,我们在PTVO设置界面的状态指示灯选择对应的P20引脚吗,勾选反转即可。
2.磁保持继电器
由于磁保持继电器(稳态继电器)的特性,其动作后将保持开关状态不再需要供电,有节能等作用。该电路采用了CN8023B作为驱动(逻辑表自行参考产品说明),R13、R14电阻外部上拉。于是,我们在PTVO的输出1和输出2设置对应的GPIO引脚IO0、IO1,并在输出1上选择稳态继电器 ON ;输出1上选择稳态继电器 OFF。脉冲设置为100毫秒(该值自行参考继电器产品说明,通常为100毫秒),勾选反转,断电回复方式设置为“最后”。
3.电量检测
采用HLW8032,其通过TX引脚以串口方式向CC2530的RX引脚发送电参数信息。本电路中采用了肖特基二极管D2电阻R41作为5V和3.3V的串口电位适配(非常规的光耦)。接下来,我仅需在PTVO中设置对应的引脚、类型和系数即可。注意:本电路中HLW8032采用了非隔离方式,电路板上存在220V的高压。另,PTVO中,串口引脚RX必须定义在P02。
4.按键
除了通过手机,我们还希望在插座上直接控制通断,必须在插座上设计一个按键来直接控制。于是采用了轻触式按键SW1。在PTVO中,根据电路我们设置对应的IO口,同时选择“链接到输出 1”,这样当我们按下按键后,CC2530会自动切换插座的通断。
四、Z2M转换文件
PTVO会自动生成相应的转换文件,针对Z2M的转换文件我这里精简了一下,供大家参考。
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
const exposes = zigbeeHerdsmanConverters.exposes;
const ea = exposes.access;
const e = exposes.presets;
const fz = zigbeeHerdsmanConverters.fromZigbeeConverters;
const tz = zigbeeHerdsmanConverters.toZigbeeConverters;
const ptvo_switch = zigbeeHerdsmanConverters.findByDevice({modelID: 'ptvo.switch'});
fz.legacy = ptvo_switch.meta.tuyaThermostatPreset;
const device = {
zigbeeModel: ['86outlet'],
model: '86outlet',
vendor: 'DIY',
description: '86型墙壁插座(带计量)',
fromZigbee: [fz.ignore_basic_report, fz.on_off, fz.ptvo_switch_analog_input,],
toZigbee: [tz.on_off, tz.ptvo_switch_trigger, tz.ptvo_switch_analog_input,],
exposes: [e.switch().withEndpoint('l1'),
e.current().withAccess(ea.STATE).withEndpoint('l3'),
e.voltage().withAccess(ea.STATE).withEndpoint('l3'),
e.energy().withUnit('Wh').withAccess(ea.STATE).withEndpoint('l3'),
e.power().withAccess(ea.STATE).withEndpoint('l3'),
exposes.numeric('power_factor', ea.STATE).withEndpoint('l3').withUnit('cosf').withDescription('Power factor'),
],
meta: {
multiEndpoint: true,
},
endpoint: (device) => {
return {
l1: 1, l3: 3,
};
},
icon: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMAAAABAAEAAAAAAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCAA6ADkDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJip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I+DtArvMEFvyNcV8fPBfiL4jfC/UNB8P6tHoV9qyray6mmVnsY3kRZZrcbWHnpEZZIt2AJkh3Erurq9E0aHw/o1nYWvnfZ7GGOCLzZ3nk2IoVd0khLucAZZyWbqSSSaPMC3j5h9aTOR/Kg/KT79KN+fb6ULUB27GfQ/pTd4/yacTnt+dN/wCAr+VCAbbH/R4/90fyqSuZsL+c6TA3nTbvKTnefSqOoatdRltt1cL9JDV8oHZ8UuRXmF34j1BD8t9eD6TN/jXPaj4y1iO4YLqupKPQXL/41PKB7cy7v4qRUANeJTeMtYVR/wATXUv/AAJf/Gqb+N9aBP8AxN9U/wDAp/8AGjlA97X5VpmB7/nXgtv431ppY86xqhy4BzdSf412X/CQX/8Az/Xn/f5v8aahcD//2Q==',
};
module.exports = device;
五、其它
如想直接复刻,可在嘉里创开源平台直接打开本工程(点击这里)。如有兴趣复刻,可留言,我再提供元器件的具体信息。
|