Another "requests" not found

Python and python framework

Moderator: leecollings

Post Reply
MikeVanD
Posts: 8
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Another "requests" not found

Post by MikeVanD »

The last three days I've pulling my hair out to get Python to work.

I've got Domoticz installed in Docker Compose and is working great.
Last week I wanted to automate a dimmer, because the steps it takes with the fysical dimmer are too big. Since I know Python a little I guess it would not be so hard...

To change the value I have to use dit packege "requests", but that is not available.
I tried everything to get it installed; I tried the pip, the pip3, the apt... but the error "Error: ModuleNotFoundError: No module named 'requests' " keeps coming back. I even went into the docker of Domoticz and tried to install the package there, but nothing.
I've digged through this forum en tried what I could find, but also nothing.
I tried dzVents, but that is a compleet new study and I do not like the use of the devicenames a lot. I'd rather use the idx.

Is there anybody out there that has the answer?
lost
Posts: 660
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Another "requests" not found

Post by lost »

Hello,

You can use idx as well as device names in Lua/dzVent. And on same localhost, no need for request/get actions: All done using tables, no external dependencies.

Lua is really easy to learn compared to Python, dzVent maybe also but my brain is really reluctant with the triggers etc... and I also like to be able to try code snippets out of Domoticz integration, directly from a side installed interpreter on the system: Pure Lua (as Python) allows this but (you can even fill some test tables as Domoticz event system would do) dzVents does not.

So, if idx is your prefered way no need for python. Did not go Docker myself (IMO, that's really multiplying the maintenance job: From system wide singletons, you multiply all by the containers nb), but if you already tried to add dependencies in the container I have no suggestion.

As a work-around, you may use system wget/curl commands from python if they work from your docker stuff...
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Another "requests" not found

Post by waltervl »

With Dzvents you can use idx too, instead of domoticz.devices('My Device') use domoticz.devices(123)

I would not recommend python for event scripting. The community for Dzvents in Domoticz is way bigger.
Dzvents is not that hard. Just try the examples on the forum and read the extended wiki: https://wiki.domoticz.com/DzVents:_next ... _scripting

It is based on Lua so for the basic instructions read this: https://www.lua.org/manual/5.4/
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
gizmocuz
Posts: 2548
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Another "requests" not found

Post by gizmocuz »

When you use docker, in the config folder you could create a file with the name 'customstart.sh' (this is explained on the docker page)

In here you could let it install packages, for example my content is

pip3 install aiohttp

it will install aiohttp when the docker is started
Quality outlives Quantity!
MikeVanD
Posts: 8
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Re: Another "requests" not found

Post by MikeVanD »

@waltervl and @lost
Thnx! I guess I have to dig a little deeper in LUA or dzVents. I prefer working with idx, because of the idiot long names I make up an change them overtime :roll:
I've tried curl to update the dimmer, but I need to import 'subprocess' for that and guess what ;-)

@gizmocuz
thnx! I tried that too, but did it again just now. I put the customstart.sh in /opt/domoticz.2024-2/config and this time I added a linie with "touch it.wrks', but the file is never made. I've tried the same in the directory '/opt/domoticz.2024-2/userdata' but that too does not work. I made the file executable and that doesn't do anything either.

I'll guess I have to learn a new language :mrgreen:
lost
Posts: 660
Joined: Thursday 10 November 2016 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Another "requests" not found

Post by lost »

MikeVanD wrote: Monday 27 January 2025 11:42 Thnx! I guess I have to dig a little deeper in LUA or dzVents.
(...)
I've tried curl to update the dimmer, but I need to import 'subprocess' for that and guess what ;-)
Python is good when it's rich modules choice really makes things easier, but the drawback is maintenance over time (modules maintenance, language evolutions). For anything that remains simple Lua (and probably dzVent derivative) is IMO much better: I have some scripts that did not change since 9 years when I started with Domoticz. In Python, several reworks would have been needed.

To just call some system commands that will complete quickly (tune timeout calling options if needed), standard os module should do the job so you may not need to install subprocess (with same issue!):

https://www.geeksforgeeks.org/python-os-system-method/
MikeVanD
Posts: 8
Joined: Friday 09 September 2022 10:32
Target OS: -
Domoticz version:
Contact:

Re: Another "requests" not found

Post by MikeVanD »

I guess you are right...

I've seen the os-option, but that is digging through all the layers; Domoticz, Docker, Linux to make a change in Domoticz feels a bit weird.

I've been testing a bit with Lua, but run into some other problems which I also seem to have with curl and with Python when I run it outside of Domoticz. But that is something for another sub board.
User avatar
waltervl
Posts: 5853
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Another "requests" not found

Post by waltervl »

If you are new to scripting please dig into Dzvents...
Curl is done with openURL() and asynchronous so it will not interfere with other threads.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest