Looking for optimal datastructure

Hi guys,

based on @ThomDietrich miflora deamon, i’d like to setup a little rule that gives me a short hint if i have to water and/or fertilise my plants . To determine that i like to compare if the actual value of moisture is between min and max value. This should be done for all plants. Now i am looking for a datastructure that ist optimal to hold name and min and max values for water and fertilisation.

At the moment i think of hashmaps with the plant name as key or a ArrayList with json that hold all the data for a plant.

any other suggestions.

Thomas

I would use Items and a Group or Design Pattern: Associated Items to link the three together. Then the rule would be something like:

PlantsMoisture.members.forEach[moisture |
    val curr = moisture.state as Number
    val min = PlantsMoistureRanges.findFirst[min | min.name == moisture.name+"_Min"].state as Number
    val max = PlantsMoistureRanges.findFirst[max | max.name == moisture.name+"_Max"].state as Number

    if(curr > max){
        // Alert that plant is too wet, use DP: Human Readable Names to use a nice name in the alert
    }
    else if(curr < min){
        // Alert that the plant is to dry
    }
]

You don’t say what you want to do with fertilization, but I suspect the same could be used.

With this approach, you can use a setpoint or slider in your sitemap to set your min and max values instead of having them hardcoded in rules. You would probably want to set up persistence on those Items too so your custom values survive a reboot. You also might need a System started rule to populate the min and max values the very first time after creating the Item

@rlkoshak

Great idea to use items to store the min and max values in items and group them and not to hard code the values.

Currently i have 7 pants and that makes 14 items for moisture and another 14 for fertilization. Based on this there is a lot of effort to build the sitemap. In addition i will never change the values, only if the is new plant in my home.

So i stay with the hashmap approach and build the rules and give it to the community and see if someone has additional ideas.

Thanks
Thomas

So just populate your Items with a System started rule. No one said you have to put them on a sitemap. That could be handy if you want to adjust the values over time but certainly not a requirement.