Skip to content

Instantly share code, notes, and snippets.

@FriesischScott
Last active April 20, 2021 11:16
Show Gist options
  • Save FriesischScott/6760a5548c6ebb0bb4e1e9faf0b85213 to your computer and use it in GitHub Desktop.
Save FriesischScott/6760a5548c6ebb0bb4e1e9faf0b85213 to your computer and use it in GitHub Desktop.
CO2 content of the beer based on the beer temperature and CO2 head pressure
function carbonation(P, T) {
return (P + 1.013) * Math.exp(-10.73797 + (2617.25 / (T + 273.15))) * 10
}
@riegelbrau
Copy link

Thanks a lot!

@riegelbrau
Copy link

It works as expected:
grafik
My script in openHab:
`var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.rule.' + ctx.ruleUID);

press = parseFloat(itemRegistry.getItem("TPMS_8a8eb4_press").getState(),10)
temp = parseFloat(itemRegistry.getItem("TPMS_8a8eb4_temp").getState(),10)

logger.info("FR press: "+press);
logger.info("FR temp: "+temp);
carbo = carbonation(press/100, temp)
logger.info("FR carbo: "+carbo);
events.postUpdate("TPMS_8a8eb4_carb", carbo);

press = parseFloat(itemRegistry.getItem("TPMS_8a8e6a_press").getState(),10)
temp = parseFloat(itemRegistry.getItem("TPMS_8a8e6a_temp").getState(),10)
logger.info("RL press: "+press);
logger.info("RL temp: "+temp);
carbo = carbonation(press/100, temp)
logger.info("FR carbo: "+carbo);
events.postUpdate("TPMS_8a8e6a_carb", carbo);

function carbonation(P, T) {
return (P + 1.013) * Math.exp(-10.73797 + (2617.25 / (T + 273.15))) * 10
}`

@FriesischScott
Copy link
Author

Very cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment