DC Load - Data input nit available
I created a new calc for the Derived Data plugin to calculate the total DC load. One of the data points is the DC output of the shore power charger. But, when I am away from the dock and the shore power charger is off, the calc does not work. It works if I turn off the charger and it still has AC power, because the output is 0. But, when it is off with no AC power, it does not exist.
How do I check for this and have the calc decide what calculations to use?
Thanks.
14 Replies
If data for the path exists (there has been some data for it since server’s start) it should work, using the last value. Or am i misunderstanding you somehow?
So you are saying the total DC load is the sum of a bunch of load, but when <Shore Power DC> is missing, the calc never takes place, because it is missing? Can Data Fidler set a value to zero if the value is missing or could Node Red? that may be a work around, but not sure if that functionality was built into Derived Data
You are correct that if there is data since the server is started it works. But, restart the server and it does not work because one of the data points in the calc is no longer there. I’m out on anchor, did some updates to plugins, restarted the server and it no longer calculates. I have been trying to figure out how to check if the days points are there and if not ignore them - actually use a different calc. Not sure how to do that in a if statement.
You can add a basedelta to set it to zero on server start. But that is cumbersome for end users
Share your code, hard for others to help otherwise
Also: do you plan to add this to derived data? If not installing future versions of the plugin may delete your calculation. For personal custom calculations I recommend Node-RED
I do plan to add this to derived data. I always make a copy of my custom calcs and back them up. Then I can restore them if they are not there after an update. Had that happen the first time I updated it and learned my lesson. Thediscord
Here is the code I have
module.exports = function (app , plugin) {
return {
group: 'electrical',
optionKey: 'DC Load',
title: 'Total DC Load',
derivedFrom:[
'electrical.batteries.0.current',
'electrical.batteries.0.voltage',
'electrical.batteries.2.current',
'electrical.batteries.2.voltage',
'electrical.chargers.293.current',
'electrical.chargers.293.voltage',
'electrical.venus.totalPanelPower'
],
calculator: function (bat0c , bat0v , bat2c , bat2v , bat10c , bat10v , stp) {
var bat0p = bat0c * bat0v
var bat2p = -bat2c * bat2v
var bat10p = bat10c * bat10v
if (bat2c <= 0) {var dcl = bat0p + bat2p + bat10p + stp} else {var dcl = bat0p + bat10p + stp}
return [ { path: 'electrical.dc.dcload', value: dcl } ] } } } The chargers.293 is the shore power charger. The data is coming from another RPi running Venus.OS and I have the Venus plugin installed and configured in SK. I am back at the dock, plugged into shore power, but have not turned on the charger and it is working (it has AC power but is off). batteries.0 is the alternator, batteries.2 is the house battery and totalPanelPower is the total power from solar panels.
if (bat2c <= 0) {var dcl = bat0p + bat2p + bat10p + stp} else {var dcl = bat0p + bat10p + stp}
return [ { path: 'electrical.dc.dcload', value: dcl } ] } } } The chargers.293 is the shore power charger. The data is coming from another RPi running Venus.OS and I have the Venus plugin installed and configured in SK. I am back at the dock, plugged into shore power, but have not turned on the charger and it is working (it has AC power but is off). batteries.0 is the alternator, batteries.2 is the house battery and totalPanelPower is the total power from solar panels.
This approach will not work very well, as each system will have different subsystems and ids
So the way derived data works with a set of known paths is not applicable to this problem
One way to do this would be to periodically use https://demo.signalk.io/documentation/develop/plugins/server_plugin_api.html#appstreambundlegetavailablepaths and then start listening for value updates for relevant paths with https://demo.signalk.io/documentation/develop/plugins/server_plugin_api.html#appstreambundlegetselfstreampath
Server API - Signal K Server Documentation
A Guide for users and developers.
i do a similar calculation - but using nodered.
to get around this type of problem, i put an “initialise nodes” (inject node setup for a once off at 0.5s aftervrestart)
in “parallel” with the input nodes, and set it to null . so that way the nodered flow initiliases the path to “null” .. so its in the paths,
and hence when i use a “math” node it just “ignores” it as part of the calc.
i use a “ Math” node which seems to work ok with “null” data .. but zero works also
if you wish to use nodered instead - i can post an example of the flows im using
I am not using nodered but am interested in how you did it.
Maybe I can make two calcs in the code and compare them in Derived data and post whichever is valid. I’ll have to think about that.
To me it sounds like you may be going in the wrong direction, making very specific something that should or could be generic
PM sent with flow and description
Not sure how I should be going about this. This is not a critical data point and I can see what my system is doing without it. But, it would be nice to have all the time and figuring it out is helping me learn how this all works.
sure! I'll try to rephrase: tackling the problem with if then elses probably won't lead to a generic solution that could be added to Derived Data for everybody
Thanks. Makes sense. I’ll keep working on it