Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace old counter from OpenEVSE module with new EnergyMeter class on ESP #556

Merged
merged 5 commits into from
Mar 11, 2023

Conversation

KipK
Copy link
Collaborator

@KipK KipK commented Mar 1, 2023

Depends new network branch to be migrated first.
now gives :

  • session_elapsed
  • session_energy
  • total_energy
  • total_day
  • total_week
  • total_month
  • total_year
  • total_switches ( number of time the relay/contactor has turned on/off )

Old OpenEvse total is imported to new counter when migrating first time, then a flag prevent to import it again if counters are reset.

fix #484

@matth-x
Copy link
Collaborator

matth-x commented Mar 1, 2023

Hi @KipK , these lines were a workaround for reading the updated total energy register during a charging session:

https://github.com/OpenEVSE/ESP32_WiFi_V4.x/blob/59fcb6881232c0ba142ee52de9601c544865c87a/src/ocpp.cpp#L157-L160

The OCPP class expects the energy regsiter reading which accumulates all energy consumption over the lifetime of the EVSE. With the newest EnergyMeter class the workaround should be obsolete and can be removed:

        return (int32_t) evse->getTotalEnergy();

Can you replace those lines?

@KipK
Copy link
Collaborator Author

KipK commented Mar 1, 2023

return (int32_t) evse->getTotalEnergy();

done thanks

@matth-x
Copy link
Collaborator

matth-x commented Mar 1, 2023

Didn't see that you already updated it in the meantime. Yes, looks perfect 👍

@KipK KipK force-pushed the EnergyMeter branch 2 times, most recently from cc5c245 to 7cdd51e Compare March 8, 2023 22:31
@KipK
Copy link
Collaborator Author

KipK commented Mar 8, 2023

I've rebased the branch for review not network manager has merged.

@jeremypoulter
Copy link
Collaborator

Can you remove the draft status if good to go?

@KipK KipK marked this pull request as ready for review March 8, 2023 23:42
@KipK KipK force-pushed the EnergyMeter branch 2 times, most recently from 6d476cc to be3a376 Compare March 9, 2023 22:31
@KipK
Copy link
Collaborator Author

KipK commented Mar 10, 2023

I still have one last problem with this branch, the input.cpp loop doesn't seems to run as I don't get the create_rapi_json esach 30 sec anymore.
Haven't found yet what I have removed that create this issue

@KipK
Copy link
Collaborator Author

KipK commented Mar 10, 2023

I still have one last problem with this branch, the input.cpp loop doesn't seems to run as I don't get the create_rapi_json esach 30 sec anymore. Haven't found yet what I have removed that create this issue

I have found, it's because I've removed the getEnergyFromEvse(), was called each 2 sec and was triggering:
_data_ready.ready(EVSE_MONITOR_ENERGY_DATA_READY);

without this input.cpp is not waken up anymore while not charging
My last commit is more a hack than a solution, @jeremypoulter what would be the best way of fixing this ?
The getEnergyFromEnergyMeter I've added is just triggering _data.ready, I guess we can change this for a better way and remove the EVSE_MONITOR_ENERGY_TIME loop, has it's not needed by EnergyMeter

@jeremypoulter
Copy link
Collaborator

I need to check, but I think all you have to do is remove EVSE_MONITOR_ENERGY_DATA_READY from the bits that define when the data has all been fetched

@KipK
Copy link
Collaborator Author

KipK commented Mar 10, 2023

Thanks, looks clear now. I'm fixing this

@KipK
Copy link
Collaborator Author

KipK commented Mar 10, 2023

ok fixed & rebased

platformio.ini Outdated Show resolved Hide resolved
platformio.ini Outdated Show resolved Hide resolved
src/energy_meter.cpp Show resolved Hide resolved
src/energy_meter.cpp Outdated Show resolved Hide resolved
src/energy_meter.h Show resolved Hide resolved
src/web_server.cpp Show resolved Hide resolved
src/web_server.cpp Show resolved Hide resolved
src/web_server.cpp Show resolved Hide resolved
src/web_server.cpp Show resolved Hide resolved
…module

Published properties:
 - session_elapsed : sec
 - session_energy  : wh
 - total_energy    : kwh
 - total_day       : kwh
 - total_week      : kwh
 - total_month     : kwh
 - total_year      : kwh
 - total_switches  : number of times the relay has been commutated

Evse counter is imported one time only. If counter is manually reset again, it won't import it the second time.

add new api endpoint /emeter
 DELETE { "hard": 0|1 , "import": 0|1}

edited api.yml
@jeremypoulter jeremypoulter merged commit 6da0ffe into OpenEVSE:master Mar 11, 2023

void EnergyMeter::increment_switch_counter()
{
if (_switch_state != _monitor->isActive())
Copy link
Collaborator

@jeremypoulter jeremypoulter Mar 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just spotted a bug, I think this should be isCharging to reflect switches of the relay, isActive will increent the count in other cases, eg if the car is not plugged it and the state toggeles from active to disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request : Daily Energy Counter
3 participants