It is not easy to dig into all the deatils of your development process and so i try to rebuild things in examples and then change them step by step. Beginner problems.
So next step look at the RequestFileLoadEvent … Found it … Did i get it now right, that params is the placeholder for the param path in the configuration yaml?
And then i have to decide which approach to go “many Rules” or only “one Rule”
No, it’s literally just params/. You can name your parameter folder how you want.
The prefix name is not related to the configured folder - it’s always params/ for parameters.
Yea - the docs could definitely be improved. I’m already working on it for the 0.19.0 release.
With great power comes great responsibility.
Imho it highly depends on the logic you want to implement.
However rules are inexpensive so why not create many of them.
If you want to transform the value in multiple rule files you can use a Parameter and create key/value pairs in the file.
param = DictParameter('my_file')
param[key]
If you want to transform in just one rule file you can create a global dict and simply use it and look up.
If you want to do more complex stuff you can use an HABApp Item as proxy
Using the transforms from openhab is (currently) not possible and to be honest I never saw the need for them.
Key “plants” is used to iterate through all plant items (Have choosen the approach with only one rule. ;-)) From key States i generate a dictionary to do the mapping with
# Get plant state mapping
self.plant_states = dict(HABApp.DictParameter('plantcare', 'states').value)
log.info(f'State changed from "{self.plant_states.get(last_state)}" to "{self.plant_states.get(target_state)}"')
Next step is to add locations (a new parameter file) and plant names
Have you guys moved to OH3 yet? I am trying to move more and more of my rules over to HABapp before the upgrade. This is another advantage of HABApp: reduce coupling. The chance of HABApps and OH upgrade at the same time is very low. And as we mainly use OH3 for its core, binding and definition of items, our upgrades should be a lot less painful than when we’re fully within OH. At the same time, we have another process/system to maintain.
When I have sometimes, I will write up a section on “Why HABapps and how is it difference from other approaches?”.
I think we should also have a section that reference source code / projects that based on HABApps. It will provide examples for people new to the project.
for name, params in HABApp.DictParameter('plantcare', 'plants').items():
PlantStatusUpdater(name, config['param1'])
Also if you cache the parameter value you might as well put a global dict in your rule files.
It’s either
self.plant_states = HABApp.DictParameter('plantcare', 'states') # note you don't have to cast to dict
log.info(f'State changed from "{self.plant_states.get(last_state)}" to "{self.plant_states.get(target_state)}"')
or
PLANT_STATES = {-1: 'deaktiviert', 0: 'OK', ... }
...
log.info(f'State changed from "{PLANT_STATES.get(last_state)}" to "{PLANT_STATES.get(target_state)}"')
I am still on 2.5 since I don’t have a lot of time right now and I’d like to fix some issues before I migrate.
That would be nice. You can create a new thread so we can get a discussion going.
I was scratching my head yesterday trying to work around this strange issue. On the HABApp side, I attempted to set a String item to an empty string value like this:
Also, I’d use oh_post_update since oh_send_command might not work as intended depending on your autoupdate settings.
You then can check the events.log and HABApp_events.log and observe the state change.
Posting an empty string as an update definitely works, I do this in one of my rules, too.
Thanks, I will try oh_post_update.
In this case there is no physical devices involved. Or, ie. Habapp is the the interface to the hardware.
It is my intention that the openhab item(s) and changes to them to be picked up by my older rules.
Yes, but this is not specific to HABApp but openhab logic.
SendCommand sends something to a physical device. postUpdate will change the state of the item.
There is this autoupdate mechanism that changes items if you issue a sendcommand, that’s where the confusion comes from.
Thanks, Reading into the docs and explanations I think I get it:
sendcommand can only be a command and not a state. NULL is a state. For example: ON or OFF is a command for a Switch item.
One more question:
Is the contents of config.yml stored somewhere in HabApp and accessible from rules?
More specific; it would be great to get the location data from one defined place.
Also, some of my rules need to store some data (caches and reports). So a directory for these things could be defined under “directories:”
I believe that these belongs in the main config rather than in separate parameter files.
It would ease moving/copy rules between systems that are not identical.
I think it is available as HABApp.CONFIG. Just check with your IDE, it will autocomplete.
Currently there is no proper way to modify this config from a rule. You can read it but you should not attempt to write it.
I just use one parameter file (the built in from HABApp) for the setup of the system, e.g. different API tokens, etc. You can structure it nicely and HABApp reads it for you.
Read only is fine, this is system administrator stuff and not something a more or less competent HABApp rule writer (me) should dabble with.
With my system administrator hat on;
I still want to propose a entry for a general data directory in config.yml
One could name it “data”,“misc” or something else.
It would simplify setting up HABApp and move rules between very different machines.
@Spaceman_Spiff
Thank you for answering my questions!
And a much bigger thank you for the work on HABApp!
For me HABApp is the thing that really lifts my home automation up.