Trying to use persistent variables to save last nozzle temperature

Basic Information:

Printer Model: ender 3 s1 pro
MCU / Printerboard: creality s1 board, orange pi 5b
klippy.log klippy.log (4.3 MB)
custom macros file:
custom_macros.cfg (1000 Bytes)

Describe your issue

I am trying to use persistent variables to save my last nozzle temperature so i can use it as an appropriate temperature in my change filament macros.
I have included [save_variables]
filename: ~/printer_data/config/variables.cfg in my printer.cfg. it will save the value to variable.cfg under the heading [variables] but then everything will stop working.
After i restart it says “Section ‘variables’ is not a valid config section”
ive tried renaming stuff and including the variables.cfg in my custom_macros.cfg and my printer.cfg. Not sure what im supposed to do.

Hello @bbqchickenman !

Why do you want to change the hotend temperature during filament change?

All the techniques I know for that do not change the temperature.

Hello there, my goal is not to change the temperature but to record the last temperature printed at, so I can have an appropriate temperature applied when I have the printer change the filament for me. (To keep from over or underheating the filament when it is removed or purged)
I suppose my wording was a little confusing, I meant change between uses of the macro, not during the use of the macro.

I plan to eventually save the filament type and have a preset for each one so the temperature is set perfectly, but as I am still figuring out persistent variables I want to keep it simple

This is exactly what I do and it works great. I think your problem is that when using save_variables, you don’t include the variables.cfg in your config file. So per the documentation, your config file would have the [save_variables] section that specifies the filename where the variables will be stored, and that’s the only reference to that file that should appear in the config. Don’t try to also include that file in the config file itself. In fact, I would suggest calling your variables file something like variables.txt just to help remind you that it’s not a cfg file.

The SAVE_VARIABLE command won’t (and shouldn’t) make any changes to the config file itself, it simply writes the variable and assigned value to the defined variables file.

I assumed i had to include it because i have to include other files in the printer.cfg so i was doing it to be safe. I removed the [include variables.cfg] from everything and renamed it like you recommended. klipper is no longer complaining about a bad config section, however it does not update the variable. Ive changed the value of LAST_PRINT_TEMP manually and it doesn’t change back when i run my start print macro

I’m not sure what you mean when you say you “changed the value of LAST_PRINT_TEMP manually,” or what you’re expecting to happen when you execute your macro. If you mean you edited the variable file by hand, that won’t work unless you stop the klipper host process first, make the change, and then restart the host process. Klipper reads the variable values at startup and then assigns them to a dictionary in the printer object. It tracks any changes to the saved variables in memory and writes them to the file when saved (if they’re changed) but it doesn’t re-read from the file unless the host process is restarted.

If you want to test to make sure the macro is working as expected, just issue these three commands one at a time:


After each one, cat your variables.txt file. You should see the new values of the saved variable reflected.

yes i did edit the variable by hand, and i understand what you have explained to me for the most part. however i am not sure how to cat my variables.txt file or what that really means. I looked it up so i think i understand what it is but i don’t know how to implement it, i couldnt find anything relating specifically to klipper

Sorry, I was making assumptions that I probably shouldn’t have. cat is a Linux command that essentially displays the content of a file. I was assuming that you had established an ssh terminal session with the Klipper host machine and had used standard Linux commands to manually edit the variables file, in which case you could simply cat the file to see its current contents.

If you are using a web frontend such as in Mainsail to view or modify file contents, I’m not sure whether the expected behavior would be different, as I’m not sure whether Mainsail immediately writes to the local file, caches file contents, etc. Maybe you can see the changes to the stored variable simply by reopening the file in the web frontend, but if not, I’m not familiar enough with the frontends to know whether that’s because of a quirk in the frontend or if it necessarily means the file contents hasn’t changed on the disk.

1 Like

ohh I see. I was editing the file through mainsail. i was thinking about it and realized that my save variables was defined in my printer.cfg not in my custom_macros.cfg, i moved it and now all is well. thank you for your help, it seems there were many small issues that needed fixing.

for anyone reading this later, my issues were that i was including my variables.cfg in my printer.cfg, and that i had defined my save variables in the printer.cfg and not in my custom_macros.cfg

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.