Rule for calculating the cost of electricity

rule “PZEM_Energy_WH”
when
Time cron “0/45 * * * * ?” //каждые 45 сек
then
logInfo(“test”, “My rule has started”)
var Number KWh = PZEM_Energy_WH.state as DecimalType
logInfo(“test”, “Variable KWh is {}”, KWh)
var Number Kal
var Number Dif
var Number Pri

if (PZEM_Energy_WH.state instanceof DecimalType) {
    Kal = PZEM_Energy_WH.minimumSince(now.withDayOfMonth(1), "rrd4j").state as DecimalType //на начало месяца
    //Kal = (PZEM_Energy_WH.minimumSince(now.toDateMidnight.withDayOfMonth(1).withMonthOfYear(1), "rrd4j").state as DecimalType) //на начало года  //https://knx-user-forum.de/forum/supportforen/openhab/33557-anf%C3%A4nger
    postUpdate(PZEM_Energy_WH_Kalends, Kal.doubleValue )
   	Dif = KWh - Kal
   	postUpdate(PZEM_Energy_WH_Consumption, Dif.doubleValue )
   	Pri = Dif * 3.16 //3,16 рубля за кВт*ч
   	PZEM_Energy_WH_Consumption_Price.postUpdate(PZEM_Energy_WH_Consumption_Price, Pri.doubleValue )
   }

val CropDigital1 = String::format("%.2f", KWh.doubleValue ) //формат строки для sitemap
val CropDigital2 = String::format("%.2f", Dif.doubleValue ) //формат строки для sitemap	
postUpdate(PZEM_Energy_WH_general, CropDigital1 + " (" + CropDigital2 + " в тек.мес.)" )	   

end

2021-07-16 17:39:00.080 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘PZEM_Energy_WH-1’ failed: An error occurred during the script execution: Could not invoke method: org.openhab.core.model.script.actions.BusEvent.postUpdate(org.openhab.core.items.Item,java.lang.String) on instance: null in PZEM_Energy_WH
2021-07-16 17:39:00.330 [INFO ] [org.openhab.core.model.script.test ] - My rule has started

Thank you for your help,I set everything up,it worked.There is one question left,how can I send it to the mail now?

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