Page 1 of 1

Script to send data to Domoticz

Posted: Tuesday 07 July 2020 14:54
by glory50
Hi,

I got some temp/hum sensors type LYWSD03MMC. So I found a script (https://github.com/JsBergbau/MiTemperature2) to poll them and another to pass the values to Domoticz's virtual device. The script to pass the values is this:

Code: Select all

#!/usr/bin/python3

import os
import re
import requests
import time
import sys

domoticzserver = "127.0.0.1"
idx_temp = "57"
#Cuisine

val_temp = sys.argv[3]  # change to sys.argv[5] for calibrated
val_hum = sys.argv[4]
val_bat = sys.argv[6]

val_comfort = "0"
if float(val_hum) < 40:
    val_comfort = "2"
elif float(val_hum) <= 70:
    val_comfort = "1"
elif float(val_hum) > 70:
    val_comfort = "3"

res = requests.get(
    "http://"
    + domoticzserver
    + "/json.htm?type=command&param=udevice&idx="
    + idx_temp
    + "&nvalue=0&svalue="
    + val_temp
    + ";"
    + val_hum
    + ";"
    + val_comfort
    + "&battery="
    + val_bat
)
The problem is that it doesn't update anything on Domoticz. The JSON URL does the job well manually but in the script, it doesn't. Can you suggest what is wrong here?

Re: Script to send data to Domoticz

Posted: Tuesday 07 July 2020 15:19
by waaren
glory50 wrote: Tuesday 07 July 2020 14:54 The problem is that it doesn't update anything on Domoticz. The JSON URL does the job well manually but in the script, it doesn't. Can you suggest what is wrong here?
Maybe you forgot to include the port number ?
Try changing

Code: Select all

domoticzserver = "127.0.0.1" 
to

Code: Select all

domoticzserver = "127.0.0.1:8080" 
or another port number you use for domoticz

Re: Script to send data to Domoticz

Posted: Tuesday 07 July 2020 17:41
by glory50
My domoticz runs on 80/443 but the URL http:// itself turns to the port 80. Yes, I tried also to add the port ":80" to the end of the IP-address without no luck. Something else must be wrong here.

Re: Script to send data to Domoticz

Posted: Tuesday 07 July 2020 18:22
by waaren
glory50 wrote: Tuesday 07 July 2020 17:41 My domoticz runs on 80/443 but the URL http:// itself turns to the port 80. Yes, I tried also to add the port ":80" to the end of the IP-address without no luck. Something else must be wrong here.
If I test the python script with

Code: Select all

./scriptname.py '' '' 25 50 '' 99 
it works as expected.
  • if you test the script with these parms what do you see?
  • do you see anything in the domoticz or system log?
  • local Networks (no username/password): set for 127.0.0.* and ::1 ?
  • what is the result of the comand which python3 ?

Re: Script to send data to Domoticz

Posted: Tuesday 07 July 2020 18:41
by glory50
I got it to work when replaced 127.0.0.1 with real ip-address 192.168.1.33. It's very strange, why it did not with lo...

Re: Script to send data to Domoticz

Posted: Friday 10 July 2020 10:23
by FlyingDomotic
If authentication is enabled, you may check that 127.0.0.1 is allowed to bypass it.