Flukso To Pvoutput - (bypassing the flukso server) - Script Discussion

The sun has just come up and the inverter has started up generating more than 50w. So the other side of ,my IF’s are being tested.

It works !!

2024-06-12 07:40:01 - Payload: {‘d’: ‘20240612’, ‘t’: ‘07:40’, ‘v2’: 51.239999999999995, ‘v4’: 872.76, ‘v11’: 51.239999999999995, ‘v12’: 872.76}
2024-06-12 07:45:00 - Initial payload: {‘d’: ‘20240612’, ‘t’: ‘07:45’, ‘v1’: 0, ‘v2’: 67, ‘v3’: 0, ‘v4’: 1057, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 67, ‘v12’: 1057}
2024-06-12 07:45:00 - Adjusted payload: {‘d’: ‘20240612’, ‘t’: ‘07:45’, ‘v1’: 0, ‘v2’: 56.28, ‘v3’: 0, ‘v4’: 887.88, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 56.28, ‘v12’: 887.88}
2024-06-12 07:45:01 - Sent data to PVOutput: 200 OK 200: Added Status
2024-06-12 07:45:01 - Payload: {‘d’: ‘20240612’, ‘t’: ‘07:45’, ‘v2’: 56.28, ‘v4’: 887.88, ‘v11’: 56.28, ‘v12’: 887.88}

This problem is a lot easier to solve in a version 3 Flukso as no IF statements are required. I will write some words on what I was trying to solve with the IF and why its much easier with the V3. Will do that shortly.

This solution using your scipt allowing the transfering of the Flukso data direct to Pvoutput is now working BETTER than Pvoutput getting the data from the Flukso site. It has solve problems with the data upload for the first time, I am still very impressed and thankfull for this script.

Not sure how many others have implemrnt this solution for their existing Flukso units so they are not thrown in the bin.

Will write up some words on v2 thus v3 shortly.

Thanks
Chris

I need the rules to work properly and then it wouldn’t be as much of a drama.

Iv spent way longer on this than I hoped. But there’s always just 1 little thing to fix… :man_facepalming:

Yes I can imagine how time consuming it has been for you, as you say, you are always finding some additional little thing to fix and make it better.

I likewise have spent a lot of time on this, so I will be glad to tidy things up and finnish the project.

Thanks
Chris

This is my very 1st attempt at this as I only “just” got the new pi 400 working after a lot of messing about.
After 4 hours I can now see it on my pc using ssh and putty.

Sorry but I am stuck at

  1. Create flukso2pvoutput_mqtt.py - download the flukso2pvoutput_mqtt.py file from here and save/move it to /home/pi/
    As before I copied and pasted into terminal (putty) as per commands above but it says no such file or directory.
    I must be doing something basic wrong?
1 Like

yeah maybe not explained properly.

ill explain what i do.
on my laptop I use winscp and putty to access my pi via ssh
where the winscp is installed on the laptop copy the (downloaded) putty.exe to the same directory

open the browser on the laptop go to GitHub - B-Mqn/FluksoToPvoutput: Send Flukso data to Pvoutout
click the green “code” button and download zip

extract those files on the laptop.

log into root on the pi via ssh (winscp) this gives you folder and file privileges you don’t have if logging in as pi. (theres a putty option here. I use that for doing the commands)
find and drag the files to the pi in the /home/pi/ directory… if you don’t have it create it

copy(drag) the service file to /etc/systemd/system

then continue following the the readme.

I don’t know how to use linux, git hub or python so im sure there’s better and easier ways around doing it but here we are :ok_hand:

1 Like

@cwjames I think I have solved the multiple rules…

it requires a few tweaks to the code. will do a thorough test tomorrow night … (I need a semi early night this month!)

Edit:
i have uploaded it here for you to test if you wish. GitHub - B-Mqn/FluksoToPvoutput at B-Mqn-patch-1 its only the main script that has changed so just do whatever you do to get it to the device.

you can keep everything above the line (below). EXCEPT for the actual rules themselves as they have changed slightly. so you don’t have to retype all your settings

###################################### Don’t Edit Below Unless You Know What You’re Doing ######################################

I haven’t done much testing but from a quick test it seems to do what its meant to.

@B-Man I have loaded your patch version of the script for testing.

The first test I done the second rule appeared not to work as v2 and v4 had not changed, see below.

I then did a second test changing the order of the rules. Now v2 and v4 have changed as required but I won’t know the final test until the other side of the if has been tested this evening when the inverter shuts down.

To test the patch script, I have removed v11 and v12 and change rules as below to do two operations on both v2 and v4, see code below:

**Previous Custom Rule to overcome problem - This works **

CUSTOM_RULES = {
“v11”: “v11 * 0.89”,
“v12”: “v12 * 0.89”,
“v4”: “(v11 + v12) if v2 < 50 else v12”,
“v2”: “0 if v2 < 50 else v11”,

“v6”: “240”,

}

First Test (v2 & v4 Not Changed)
Current Custom Rule

CUSTOM_RULES = {
“v4”: “v4 * 0.89”,
“v2”: “v2 * 0.89”,
“v4”: “(v4 + v2) if v2 < 50 else v4”,
“v2”: “0 if v2 < 50 else v2”,

“v6”: “240”,

}

First Test Debug File:

2024-06-13 09:15:00 - Initial payload: {‘d’: ‘20240613’, ‘t’: ‘09:15’, ‘v1’: 0, ‘v2’: 1227, ‘v3’: 0, ‘v4’: 1039, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 0, ‘v12’: 0}
2024-06-13 09:15:00 - Adjusted payload: {‘d’: ‘20240613’, ‘t’: ‘09:15’, ‘v1’: 0, ‘v2’: 1227, ‘v3’: 0, ‘v4’: 1039, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 0, ‘v12’: 0}
2024-06-13 09:15:01 - Sent data to PVOutput: 200 OK 200: Added Status
2024-06-13 09:15:01 - Payload: {‘d’: ‘20240613’, ‘t’: ‘09:15’, ‘v2’: 1227, ‘v4’: 1039}

Second Test (Rule Order Changed)
CUSTOM_RULES = {
“v4”: “(v4 + v2) if v2 < 50 else v4”,
“v2”: “0 if v2 < 50 else v2”,
“v4”: “v4 * 0.89”,
“v2”: “v2 * 0.89”,

“v6”: “240”,

}

Second Test Debug File

2024-06-13 09:25:00 - Initial payload: {‘d’: ‘20240613’, ‘t’: ‘09:25’, ‘v1’: 0, ‘v2’: 1427, ‘v3’: 0, ‘v4’: 1038, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 0, ‘v12’: 0}
2024-06-13 09:25:00 - Adjusted payload: {‘d’: ‘20240613’, ‘t’: ‘09:25’, ‘v1’: 0, ‘v2’: 1270.03, ‘v3’: 0, ‘v4’: 923.82, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 0, ‘v12’: 0}
2024-06-13 09:25:01 - Sent data to PVOutput: 200 OK 200: Added Status
2024-06-13 09:25:01 - Payload: {‘d’: ‘20240613’, ‘t’: ‘09:25’, ‘v2’: 1270.03, ‘v4’: 923.82}

I won’t know if the other side of the IF statement works until the inverter shuts down tonight, I will let you know.

I hope I have explained the tests OK ?

Thanks
Chris

At least im learning my way slowly around pi :slight_smile:
Cannot copy the file into the "service file to /etc/systemd/system"
Tried using scp, remote desktop and locally on the pi.
All methods giving me an error. https://imgur.com/7f4AOl8
Got any other clues? :wink: Baz

@bazzle
yep, you need to be logged into root if you want to do it via winscp (that’s what I do).

but if you copy it to /home/pi/

then open terminal and run
sudo cp /home/pi/flukso2pvoutput_mqtt.service /etc/systemd/system/
it should move it there with root privlidges (thats what sudo does)
then continue onto the next step.

1 Like

@cwjames

Sorry I didnt explain myself. I was quite tired.
The actual rule formatting has changed. I haven’t wrote an update on how to use it.
I worked out using the old rule format it would overwrite the first rule with the second rule for each value. hence why using v11 and v12 was working.

looking at your previous rules though
“v4”: “(v11 + v12) if v2 < 50 else v12”, and “v2”: “0 if v2 < 50 else v11”,
both looks for v2 that isn’t even a value yet? I think it should have been v12 inside the rules not v2?
or the v2 rule needed to be above the v4 rule but still reference v12

either way irrelevant now.

the updated format is the square brackets and each rule is separated by a comma

"v value":["rule 1"," rule 2","rule 3","rule 4 etc"],
 "v2": ["v2 * 0.89","0 if v2 < 50 else v2"],

try this

CUSTOM_RULES = {
   "v2": ["v2 * 0.89","0 if v2 < 50 else v2"],
   "v4": ["v4 * 0.89","(v4 + v2) if v2 < 50 else v4"],
   "v6": ["240"],
}

and this is separated out so you can see

CUSTOM_RULES = {
    "v2": [
        "v2 * 0.89",
        "0 if v2 < 50 else v2"
    ],
    "v4": [
        "v4 * 0.89",                                 # rule 1 for v4
        "(v4 + v2) if v2 < 50 else v4"               # rule 2 for v4
    ],

    "v6": [
        "240"
    ],
}

The way it works for v4
rule 1 is applied, then rule 2 uses the updated values from rule 1. so v4 in rule 2 is (v4 * 0.89) for any v4.

To ensure the rules are applied correctly, you need to process the rule for v2 before the rule for v4. This is because v4 depends on the updated value of v2. First, apply the rule for v2 (v2 = v2 * 0.89). After updating v2, apply the rule for v4 (v4 = v4 * 0.89). This sequence ensures that when v4 is compared to v2 ((v4 + v2) if v2 < 50 else v4) , both values have been correctly adjusted. If you reverse the order, v4 would be compared to v2 before v2 has been updated, leading to incorrect results.

@cwjames
this is a link to the how to of rules for your version only!
when fully tested it will be merged with the current script and the link will stop working. I will update the main post when all this happens

I will try these rules, then I will tell you tomorrow if the inverter ‘shuts down’ overnight, i.e. brings the solar to 0.

  "V2": "0 if v2 < 74 else v2 - 74",
  "v4": "v4 * 0.98",

Thank you

im not sure what release you have so the if rules might not work for your version

if you update to the new version v2 linked at the top it should handle them. (it had a name change mainly because there were so many changes I could then tell who was using what script.)

V1 = Mqtt_pvoutput # I don’t think if rules work with this version and definitely not multi rule
V2 = flukso2pvoutput_mqtt # If rules work but no multi rules
V3 = (currently testing in github patch1 branch) # If rules and multi rules assumed working… as far as know only @cwjames and Myself are using this.

@B-Man

Well I tried your updated rules with the patched script and I now get an error in the main loop. Just in case I had not updated the patch section correctly, I down loaded the complete patched script again, edited it again as required and tested it again, I am sorry to report the same error below.

CUSTOM_RULES = {
“v2”: [“v2 * 0.89”,“0 if v2 < 50 else v2”],
“v4”: [“v4 * 0.89”,"(v4 + v2) if v2 < 50 else v4"],
}

2024-06-13 18:30:00 - Initial payload: {‘d’: ‘20240613’, ‘t’: ‘18:30’, ‘v1’: 0, ‘v2’: 43, ‘v3’: 0, ‘v4’: 887, ‘v5’: 0, ‘v6’: 0, ‘v7’: 0, ‘v8’: 0, ‘v9’: 0, ‘v10’: 0, ‘v11’: 0, ‘v12’: 0}
2024-06-13 18:30:00 - Error in main loop: eval() arg 1 must be a string, bytes or code object

I hope I have not intoduced an error in changing the files, I don’t think I have.

I have activated my make shift script using v11 & v12 so all is working again.

I know this is causing you a LOT of time working on this problem so please don’t do so on my behalf as we have a working solution so there is no problem at this end. However I suspect you are keen to fix any bugs in the script so others don’t run into a similar problem with the custom rules using two rules on the same varable. If you do want to track this down further I am happy to work with you by doing any test you require. That’s if the problem is NOT at my end doing something wrong (I hope Not).

I may be hard to contact next week as I am having a Cateract Operation, but up until then I can do any testing as required.

Thanks
Chris

Is there a way to confirm I am actualy working on the patched script, I have a quick scan of the code and could not see the patched section ??

I have checked and recheck the patched file against the version before in the section below this line.

###################################### Don’t Edit Below Unless You Know What You’re Doing ######################################

Both versions I have are the same, if this is correct it would explain why the new script with the new custom rules is giving a error.

I seem to be 2 steps forward, one step back.
when I ran “python3 /home/pi/flukso2pvoutput_mqtt.py”
there was an error : No module named “paho”
I read back thru the texts and noticed when I ran

  1. Install python addons pip install requests and pip install paho-mqtt
    I dont think it worked. error: externally managed environment
    My python version is 3.11.2
    Baz

@B-Man

No problems, I think we are all getting tired…

The link you enclosed has a problem.

https://github.com/B-Mqn/FluksoToPvoutput/tree/B-Mqn-patch-1https://github.com/B-Mqn/FluksoToPvoutput/tree/B-Mqn-patch-1
404 - page not found

When I get the correct file I will setup a test enviroment including a test system on PVoutput to make testing quicker without breaking the working system.

I am glad we have found the reason why the patch script at this end was not working, I was going mental trying to work out what was wrong. We may have some more luck now…

Will await you correcting the location on github.com

Thanks
Chris

[quote=“B-Man, post:34, topic:7405”]
Hi, I have upgraded to v2 but it doesn’t work, it doesn’t show 0 when the inverter shuts down.
I am sorry

Got up early this morning to get this testing of the patched script with #v3 at the top of the file, however the link you enclosed still has the “404 - Page not found” error.

I will await a working link to the patched file.

Thanks
Chris