Find lowest value of item state (in my case energy price) with rule in Openhab

Hello everyone,

I’m currently attempting to identify the lowest value of an item’s state within a specific rule. I rely on Awattar as my energy provider, resulting in fluctuating energy prices on an hourly basis.

Upon activating the dishwasher, Alexa informs me whether we should procure energy from the grid or if we can utilize our solar energy, determined by real-time data from the inverter and solar forecast.

My aim is to configure Alexa to alert me specifically when we need to purchase energy from the grid, highlighting the instance when the energy is available at its most cost-effective rate.

So I use the following items and assigned already a group to them:

Group:Number:MIN cheapest_price "Awattar Cheapest price [%d]" 

Number:Dimensionless today00 "Today 00-01 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today00#total-gross" }
Number:Dimensionless today01 "Today 01-02 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today01#total-gross" }
Number:Dimensionless today02 "Today 02-03 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today02#total-gross" }
Number:Dimensionless today03 "Today 03-04 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today03#total-gross" }
Number:Dimensionless today04 "Today 04-05 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today04#total-gross" }
Number:Dimensionless today05 "Today 05-06 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today05#total-gross" }
Number:Dimensionless today06 "Today 06-07 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today06#total-gross" }
Number:Dimensionless today07 "Today 07-08 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today07#total-gross" }
Number:Dimensionless today08 "Today 08-09 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today08#total-gross" }
Number:Dimensionless today09 "Today 09-10 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today09#total-gross" }
Number:Dimensionless today10 "Today 10-11 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today10#total-gross" }
Number:Dimensionless today11 "Today 11-12 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today11#total-gross" }
Number:Dimensionless today12 "Today 12-13 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today12#total-gross" }
Number:Dimensionless today13 "Today 13-14 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today13#total-gross" }
Number:Dimensionless today14 "Today 14-15 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today14#total-gross" }
Number:Dimensionless today15 "Today 15-16 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today15#total-gross" }
Number:Dimensionless today16 "Today 16-17 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today16#total-gross" }
Number:Dimensionless today17 "Today 17-18 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today17#total-gross" }
Number:Dimensionless today18 "Today 18-19 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today18#total-gross" }
Number:Dimensionless today19 "Today 19-20 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today19#total-gross" }
Number:Dimensionless today20 "Today 20-21 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today20#total-gross" }
Number:Dimensionless today21 "Today 21-22 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today21#total-gross" }
Number:Dimensionless today22 "Today 22-23 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today22#total-gross" }
Number:Dimensionless today23 "Today 23-00 [%2.2f ct/kWh]"  (cheapest_price) { channel="awattar:prices:bridge1:price1:today23#total-gross" }```

Each item retains the current price information. I am able to extract the lowest value from the specified group. However, I am currently working on integrating this information into a rule structure that would enable Alexa to notify me of both the timing and the specific cost when the lowest price for energy is available. This will allow me to be informed precisely about when the most economical energy rate is accessible.

With this data, I can organize my dishwasher’s schedule according to the energy price fluctuations. Do you have any suggestions on how to make this work effectively?

Thank you in advance!

I would put all the prices in an array, find the lowest value within the array and based on the position within the array, you know what time has the lowest price

I tried it out with Blockly. This works for me (I only created three items 09 - 10 - 11 as I was too lazy to create more). Blockly allows you to produce names for items, store them in a var and then use that as an item name.

Hope that inspires you.

Update: I overlooked you already grouped them. You can also iterate over a group of icons which is even simplier:

Note that in the if condition you can also store the item name for later reference in another variable for later.

1 Like