logo elektroda
logo elektroda
X
logo elektroda

Zemismart SPM01-D2TW Energy Counter: Data Issues with Tuya MCU and ESP02S Swap

Pete0815 3309 35
ADVERTISEMENT
  • #31 21099682
    Pete0815
    Level 7  
    p.kaczmarek2 wrote:
    Wait @Pete0815, so what exactly helped?


    Mmmh, need some more testing. For a quick answer, I just changed the state query back to a one-shot from repeating every 5 sec and expecting this is it.
    BUT, the energy counter is still working fine after this.

    So very strange because of no function before. Will test more carefully to find out.

    Edit: Tested again and again but no result why.

    The autoexec.bat is now:
    // This script provides extra REST page for hosting in LittleFS
    // Please see: https://www.elektroda.com/rtvforum/topic4040354.html
    // Script taken from: https://www.elektroda.com/rtvforum/viewtopic.php?p=20990058#20990058
    // Download HTML there.
    
    // Clear all previous definitions
    clearIO
    
    // clear flags
    // flags 0
    
    // set flag 46
    SetFlag 46 1
    
    // start TuyaMCU driver
    startDriver TuyaMCU
    tuyaMcu_setBaudRate 9600
    
    // This one is better than tuyaMcu_defWiFiState 4;  MQTTState 1 = WiFiState 4
    // issuing of tuyaMcu_defWiFiState 4 continues the script,
    // but doesnt report to MQTT since there is still no connection.
    // if you didn't setup MQTT connection then issue tuyaMcu_defWiFiState 4
    // and comment waitFor MQTTState 1
    
    waitFor MQTTState 1
    //tuyaMcu_defWiFiState 4
    
    // Total energy - Dpid 1 "total_forward_energy" -> channel 4
    linkTuyaMCUOutputToChannel 1 val 4
    setChannelType 4 EnergyTotal_kWh_div100
    setChannelLabel 4 "Total Energy"
    
    // Measurements - Dpid 6 "phase_a" - channel RAW_TAC2121C_VCP -> 5,6,7
    // TAC2121C VoltageCurrentPower Packet
    // This will automatically set voltage, power and current
    linkTuyaMCUOutputToChannel 6 RAW_TAC2121C_VCP
    setChannelType 5 Voltage_div10
    setChannelLabel 5 "Voltage"
    setChannelType 6 Power
    setChannelLabel 6 "Power"
    setChannelType 7 Current_div1000
    setChannelLabel 7 "Current"
    
    
    // Fault - Dpid 9 "fault" -> channel 9
    linkTuyaMCUOutputToChannel 9 raw 9
    setChannelType 9 ReadOnly
    setChannelLabel 9 "Fault"
    
    // Prepayment on-off - Dpid 11 "switch_prepayment" -> channel 2
    linkTuyaMCUOutputToChannel 11 bool 2
    setChannelType 2 toggle
    setChannelLabel 2 "Prepayment"
    
    // Clear Energy Counters - Dpid 12 "clear_energy" -> channel 3
    linkTuyaMCUOutputToChannel 12 bool 3
    setChannelType 3 toggle
    setChannelLabel 3 "Clear Energy Counters"
    
    // Prepaid energy - Dpid 13 "balance_energy" -> channel 11
    linkTuyaMCUOutputToChannel 13 val 11
    setChannelType 11 EnergyTotal_kWh_div100
    setChannelLabel 11 "Total Prepaid Energy"
    
    // Charge Prepayment - Dpid 14 "charge_energy" - channel 12
    linkTuyaMCUOutputToChannel 14 val 12
    setChannelType 12 TextField
    setChannelLabel 12 "Purchased Energy [kWh*100], i.e. 1kWh = 100"
    
    // Settings 1 - Dpid 17 "alarm_set_1" - channel 13
    linkTuyaMCUOutputToChannel 17 val 13
    setChannelType 13 TextField
    setChannelLabel 13 "Leakage Current Protection Settings"
    
    // Settings 2 - Dpid 18 "alarm_set_2" -> channel 10
    linkTuyaMCUOutputToChannel 18 raw 10
    setChannelType 10 ReadOnly
    setChannelLabel 10 "UV, OV, Max. Current Protections Settings"
    
    // Breaker Id - Dpid 19 "breaker_id" -> channel 0
    linkTuyaMCUOutputToChannel 19 str 0
    setChannelType 0 ReadOnly
    setChannelLabel 0 "Breaker ID"
    
    // The above are read only channels. Except Settings 2 (mapped on channel 10), but since we cannot set it due to wrong parse of TuyaMCU driver - for now read only
    
    
    // NOTE: addRepeatingEvent [RepeatTime] [RepeatCount]
    // code below will forever Send query state command every 5 seconds
    //addRepeatingEvent 5 -1 tuyaMcu_sendQueryState 
    
    // AngelOfDeath - We don't need it forever, since TuyaMCU sends everything when necessary
    // we need it just first time to obtain initial status. Some dpIDs not reported without asking
     tuyaMcu_sendQueryState


    So beside Alarm Set 1 & 2 and Leakage Protection everything seems to be ok.
    Because OV, UV and Max current protection are read only I´m not sure how to set this alarm values.


    Edit2:
    Still a guess what has happened but identified a new problem/reason.

    Maybe during I struggeld getting some data my MQTT connecting was not connected/configured.
    So the autoexec.bat entry:
    waitFor MQTTState 1

    will be a problem.

    So for now, I deleted the MQTT configuration for testing and the current, power and energy counter values are missing/not send anymore.

    Then I activated
    tuyaMcu_defWiFiState 4
    in the autoexec.bat and the energy counter started to send a value but current and power still missing.

    After changing back the
    waitFor MQTTState 1
    in the autoexec.bat and configured a mqtt connection everything is fine again.

    So to achieve this status I need a working MQTT connection.
  • ADVERTISEMENT
  • #32 21100203
    p.kaczmarek2
    Moderator Smart Home
    do you have enabled TuyaMCU queue in device flags?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #33 21100333
    Pete0815
    Level 7  

    p.kaczmarek2 wrote:
    do you have enabled TuyaMCU queue in device flags?


    No it was disabled and now enabled and tested again .... very illogical results....

    After enabling TuyaMCU queue I disabled the MQTT configuration and switch from waitFor MQTTState 1 to tuyaMcu_defWiFiState 4

    Result: No reported values anymore

    Then switch from tuyaMcu_sendQueryState to addRepeatingEvent 5 -1 tuyaMcu_sendQueryState

    Result: everything fine again

    Then switch back from addRepeatingEvent 5 -1 tuyaMcu_sendQueryState to tuyaMcu_sendQueryState

    Result: everything still ok. This I do not understand.

    Edit:

    Ok, figured out that there is a difference in using the Button "Save, Reset SVM and rund file as script thread" + Restart instead of disconnecting the device from power.

    After the last test scenario, where everything seems to work (active: tuyaMcu_defWiFiState 4 & tuyaMcu_sendQueryState) I disconnected the device from power.

    Now after repowering the situation is faulty again and values like dpIx 6 (voltage, current, power) are missing / not received from MCU.

    Guess I really have to repower fully for every test scenario to get true results.
  • ADVERTISEMENT
  • #34 21126038
    Pete0815
    Level 7  
    Ok, took some time for some new motivation to test.

    I figured out 2 working configurations:

    A) Mqtt Connection + One shot query send by autoexec
    
    waitFor MQTTState 1
    tuyaMcu_sendQueryState
    


    B) Wifi state + repeating query send by autoexec
    
    tuyaMcu_defWiFiState 4
    addRepeatingEvent 5 -1 tuyaMcu_sendQueryState
    


    Because maybe I'm not using Mqtt in every configuration, I'm preferring configuration B at the moment because it should always work.

    Still have not found a way to set alarm1 and alarm2 and therefore of course also not how to activate or check if it's working.
  • ADVERTISEMENT
  • #35 21126060
    p.kaczmarek2
    Moderator Smart Home
    It seems you've found one of the causes - doing OBK reset does not reset the TuyaMCU. If you want to have a fresh start, you need to power off the whole setup, wait a moment, and power it again.

    It's not possible to reset TuyaMCU from software.
    Helpful post? Buy me a coffee.
  • #36 21126492
    vincenzoernst1
    Level 6  
    what i do is: remove vcc jumper cable, start flashing and reconnect vcc. needs some timing but works in general.

Topic summary

The discussion revolves around issues encountered while using the Zemismart SPM01-D2TW energy counter, specifically after replacing the Tuya CB2S chip with an ESP02S. The user reports receiving limited and inconsistent data points from the device, primarily only one data point changing despite attempts to modify the load. Various solutions are proposed, including using the TuyaMCU guide for setup and configuration, capturing communication data, and utilizing commands like `tuyaMcu_sendQueryState` to request data points. The conversation also touches on the importance of ensuring proper power supply and the need for a stable connection to retrieve accurate readings. Users share insights on configuring the autoexec.bat file for optimal performance and troubleshooting steps to resolve data reporting issues.
Summary generated by the language model.
ADVERTISEMENT