Plus, you really do not want to create both an Item and a variable var with the same name. They are not the same thing at all, and you will never know which your code will use when you refer to that name.
yes, I´ve installed everything as you described in you tutorial. Now I see 4 tables: Item1, Item2, Item3, Items. In ITems I can really find some items: Light_Wz_Bild, Light_Wz_Couch, Light_Wz_Deckenlampe. But it´s only 3 items out of many more…
So I want this item:
Number StromZK “Stromzählerstand [%s]” (gBM)
to display a value which is stored in a db. I have no idea what I must write in the items file to connect the Database. Or does it pull the data automatically? If so, how does it know which value I want? E.g. I want to save Time and Value…
Have another look at the tutorial.
It describes a file mysql.persist
Within that file is an editable section Items
There you tell SQL which items, or groups of items, to record ; and when to record them.
Ok, I got my Database running fine now, it´s recording my items as it is supposed to.
Now one more question in direction SQL:
the database records the behavior of my sensor with the Value OPEN / CLOSED and the time when this happens. So my table has 2 columns and a lot of rows now.
How can I manage in openhab2 that the item shows me a value e.g. 1000 as an initial value and than adds +1 whenever the sensor writes an OPEN into the database?
In the end I want to have a power consumption measurement which shows me tha actual KWh consumption / month and I also like to build a diagram where I can see at which time most power was consumed.
edit: I think I need another table, let´s name it StromZ, inside the db with the initial Value (e.g. 1000) where +1 gets added whenever item StromZK gets an OPEN!?! I have no idea how to realise this. From my expirience now openhab only generates a table for an item when it gets an update, but how should I update an item like StromZ which is not attached to a sensor?
That doesn’t seem to e a database related requirement.
I’d create a number item for counting.
Trigger a rule to set it 1000 whenever (at system start? when the date changes? when a button is pushed?)
Trigger a rule from the sensor item changing to OPEN and have that rule add 1 to the counter.