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
After changing back the
waitFor MQTTState 1
So to achieve this status I need a working MQTT connection.