Trouble setting a rule-global variable (solved)

Tags: #<Tag:0x00007f617e1a4c80>

You can define it in any file that you can address to import, /etc/openhab2/automation/lib/python/ being the preferred location.
Sorry but I won’t answer all the rest. This not a programming or Python tutorial. You are expected to learn that on your own.


Thanks for Reply and your time!

Sorry, I asked to lot: Just reacted, because persons searched to test python integration and just find out: It makes openhab2 much more complex and without examples in bindings like done for DSL its nothing for people to do!

Just find first failure in python integration: Unicodes for symbols working in DSL not working in Python

Sorry, I haven’t had a chance to respond. There are many ways to do this, but the easiest is to add what you need to the $OPENHAB_CONF/automation/lib/python/ Then use this in your scripts with…

from configuration import my_variable

No, this would be a script. You can’t create a variable in a script that is accessible from another script.

Have you read through the documentation yet? There are lots of examples here, and when people ask for something, I add it in.

Where? To make a unicode string in Python, prefix it with a ‘u’, like…

test = u"This is a unicode string and it is 39 °F"

This is included in an update to the documentation, which I hope to push today.

1 Like

Thanks a lot.

Yes, I read a lot there. But some basics maybe need more information. For example: Tried to find syntax for “if…then…else” too, maybe a sentence the “indent of text” defines the used block in if would help. Didn’t know if thats right, I googled ca. one hour to find out, found nothing and just tried out.

Small hint for ducumentation site: If opened an entry in menu: there are some Problems with Menu-Scrollbar in Firefox, so you cannot go up for earlier entries if expandes some menu-entries.

The u before String works! Thanks. I’ll try with logentries too, cause german characters like ä gives garbage in log. So I think u will be my new best friend :wink:

I will add in the use of if/elif/else statements. I’ll also mentions the lack of case statements and the importance of indentation. However, all of these are covered in the Python documentation that is linked to.

Please open an issue for this one and include screenshots. I’m not sure what you mean.

The helper libraries need all of the log entries to be reworked to use unicode. I might be able to get this in today.

1 Like

This is basic programming knowledge which IMHO is beyond the scope of what we can reasonably offer.
Scott, maybe add a prominent link to a decent resource on Python on the net such as those video tutorials by Microsoft.

There is a whole Python reference section and those MS tutorials are already in there. I tend to not include Python programming info, but something like if/else statements comes up often enough that I don’t mind adding it. However, I will also added some text about the need to read the Python docs for learning the basics.

There is a case for highlighting the particular differences for those seeking to convert DSL rules - like the absence of switch/case.

1 Like

That was really my intention for the But How Do I…? section… illustrating the differences between what you are familiar with doing in the DSL and how it is done in Python. But a section really pointing these out would be helpful…