Energy counting

What am I doing wrong ?
I have an energy meter, I count energy day and energy total. I want to count and display the sum of energy, where the price of 1 kW is 0.65 $ .

.sitemap
Text item=Dziszejsza label="Energia na dziś  [%.3f kWh]" icon="my_volt"      // *ENERGY.Today*
Text item=Wczorajsza label="Energia Wczoraj  [%.3f kWh]" icon="my_volt"  // *ENERGY.Yesterday*
Text item=Calosc label="Energia całość  [%.3f kWh]" icon="my_volt"            //  **ENERGY.Total**
Text item=Zarobek                         //   1kW is 0,65 $

.items
Number Zarobek  "Zarobek Tauron [%.2f $]" 
.rules
import java.lang.Object
import org.eclipse.smarthome.core.items.GenericItem
import org.eclipse.smarthome.core.library.items.StringItem
import java.lang.Math.*
import org.openhab.core.library.types.DecimalType

val Koszt = 0.65

rule "tauron"
when
	Item    Calosc received update
then
	

	

	var Number Zarobek = ( Koszt * Calosc.state as Number )
	logInfo("AUTOMATION", "Zarobek = " + Zarobek)
        logInfo("AUTOMATION", "Sama calosc = " + Calosc )
        logInfo("AUTOMATION", "Sama calosc = " + Calosc.state as Number)
        Zarobek.sendCommand(Calosc.state as Number * 0.65 )
        
end

log
2021-08-18 22:33:03.382 [INFO ] [se.smarthome.model.script.AUTOMATION] - Zarobek = 3.9416

2021-08-18 22:33:03.388 [INFO ] [se.smarthome.model.script.AUTOMATION] - Sama calosc = Calosc (Type=NumberItem, State=6.064, Label=Wyprodukowana całość, Category=null)

2021-08-18 22:33:03.394 [INFO ] [se.smarthome.model.script.AUTOMATION] - Sama calosc = 6.064

2021-08-18 22:33:03.397 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘tauron’: ‘sendCommand’ is not a member of ‘java.lang.Number’; line 21, column 9, length 51

The error is pretty clear. Zarobek is a Number, not an Item. If you create a variable that is the same name as an Item, that variable “hides” the Item. Either use a different name for the var Number or change the name of your Item.

Thank you for the hint, like a small problem, but for me new knowledge and solved it.

Text item=Dziszejsza label="Energia na dziś  [%.3f kWh]" icon="my_volt"
Text item=Wczorajsza label="Energia Wczoraj  [%.3f kWh]" icon="my_volt"
Text item=Calosc label="Energia całość  [%.3f kWh]" icon="my_volt"
Text item=Elektrownia icon="time"
Text item=Poczatek icon="time"
Number Elektrownia  "Zarobek Solara [%.2f zł]"

val Koszt = 0.65


rule "tauron"

when

	Item    Calosc received update
then
	

	

	var Number Zarobek = ( Koszt * Calosc.state as Number )
        
	logInfo("AUTOMATION", "Zarobek = " + Zarobek)
        logInfo("AUTOMATION", "Sama calosc = " + Calosc.state as Number)

        
        Elektrownia.sendCommand(Zarobek)

end

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