dzungpv / dnckatsw00x

Zigbee light switch with dim support base on chip cc2530
GNU General Public License v3.0
90 stars 19 forks source link

Building From Scratch help needed #8

Closed shahglobal closed 5 years ago

shahglobal commented 5 years ago

Hi, Thank you for this great learning venture. I am new to ZigBee, following your guide for building it from scratch I am not sure is "zcl_samplelight_data.c" the only file we have to edit? if yes can you share your zcl_samplelight_data.c with the edited code which will help me understand better where to add? After this, I want to recompile this with different RF channel settings to be able to communicate with zigbee2mqtt dongle in homeassistant installation. Kind Regards and thank you again.

dzungpv commented 5 years ago

@shahglobal please follow this guide: https://github.com/dzungpv/dnckatsw00x/issues/9#issuecomment-503435441

shahglobal commented 5 years ago

Excellent sir, thank you so much for your pointers. Now the switch worked just fine. I am wondering what would I need to tweak for the switch to remember the last state of the switch (on or off) after a power cycle, this will really be nice and will emulate a mechanical switch. Also I wonder what changes might be needed so that the switch status is shown at the homeassistant, I mean when I toggle the switch with the pushbutton at the module, this status is not reflected at the homeassistant web page. Thanks again for your feedback and for this great project.

dzungpv commented 5 years ago

@shahglobal to save network data https://github.com/dzungpv/dnckatsw00x/issues/5#issuecomment-503451083. You just install zigbe2mqtt for hass and then enable automatic discovery for mqtt and then it will work.

shahglobal commented 5 years ago

Hi, The switch connects to zigbee2mqtt at hass with no problem each time. But if it is power cycled, the switch boots and status led shows connected but the relay stays OFF at the same time at HASS it shows the last state, either ON or OFF. When I flip the web button by clicking at HASS web then it shows the correct state and toggles the cc2530 board no problem. Could this be an issue with my cc2530 board? As a feature request if temperature/humidity and soil moisture sensors are added to this module or an additional module will be great features too. Please email me to discuss in details. Kind Regards

dzungpv commented 5 years ago

@shahglobal yes, it is correct with current code, to have the feature update status to hass immediately after power cycle, you can add report code to the end of function zclSampleLight_Init, or just simple call function you store the report code:

//report state for button 1
  zclSampleLightSeqNumState++;
  zclReportCmd_t rptcmd;
  rptcmd.numAttr = 1;
  rptcmd.attrList[0].attrID = ATTRID_ON_OFF;
  rptcmd.attrList[0].dataType = ZCL_DATATYPE_BOOLEAN;
  rptcmd.attrList[0].attrData = (void *)(&zclSampleLight_OnOff);

  // Set destination address to indirect
  zclSampleLight_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
  zclSampleLight_DstAddr.addr.shortAddr = 0;
  zclSampleLight_DstAddr.endPoint=1;
  zcl_SendReportCmd(SAMPLELIGHT_ENDPOINT,&zclSampleLight_DstAddr, ZCL_CLUSTER_ID_GEN_ON_OFF, &rptcmd, ZCL_FRAME_SERVER_CLIENT_DIR, true, zclSampleLightSeqNumState );
  //report state for button 2
  zclSampleLightSeqNumState++;
  zclReportCmd_t rptcmd;
  rptcmd.numAttr = 1;
  rptcmd.attrList[0].attrID = ATTRID_ON_OFF;
  rptcmd.attrList[0].dataType = ZCL_DATATYPE_BOOLEAN;
  rptcmd.attrList[0].attrData = (void *)(&zclSampleLight_OnOff1);

  // Set destination address to indirect
  zclSampleLight_DstAddr.addrMode = (afAddrMode_t)Addr16Bit;
  zclSampleLight_DstAddr.addr.shortAddr = 0;
  zclSampleLight_DstAddr.endPoint=1;
  zcl_SendReportCmd(SAMPLELIGHT_ENDPOINT+1,&zclSampleLight_DstAddr, ZCL_CLUSTER_ID_GEN_ON_OFF, &rptcmd, ZCL_FRAME_SERVER_CLIENT_DIR, true, zclSampleLightSeqNumState );

I have noplanning for add sensor feature to this project, you can learn from TI sample project SampleTemperatureSensor

shahglobal commented 5 years ago

Awesome thanks for the pointers, I will test it out. I am working on a simple temperature/humidity sensor. Please email me on shahglobal@gmail.com I am willing to donate. Kind regards and thanks for your support.

shahglobal commented 5 years ago

I just tested the above changes, the switch pushbutton toggle also updates status at HASS which is great and works. The switch (Relay) is always off after power cycle, Is there any way to save the state of the switch, i.e when the switch is powered on ( or power cycled) the relay state should stay the same i.e, it should turn on or stay off depending on the last state of the relay. Thanks for your support and suggestions.

shahglobal commented 5 years ago

Hi, Of course if there is possibility at all in your busy schedule, how much of your time would be needed to help me add the SampleTemperatureSensor as a temperature sensor to this module or another module for zigbee2mqtt . Kindly respond by email. Please consider dht11/22 as a sensor. I also have a sample temperature project that came with the kit tutorials, it is done in older zstack it works between two modules and PC serial for data display, but it is not compatible with zigbee2mqtt. Kind Regards and thank you so much for your support.