Script to send data to Domoticz Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
glory50
Posts: 38
Joined: Thursday 07 June 2018 22:23
Target OS: Linux
Domoticz version: 2022.1
Location: Sud de France
Contact:

Script to send data to Domoticz

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to send data to Domoticz

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
glory50
Posts: 38
Joined: Thursday 07 June 2018 22:23
Target OS: Linux
Domoticz version: 2022.1
Location: Sud de France
Contact:

Re: Script to send data to Domoticz

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script to send data to Domoticz

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
glory50
Posts: 38
Joined: Thursday 07 June 2018 22:23
Target OS: Linux
Domoticz version: 2022.1
Location: Sud de France
Contact:

Re: Script to send data to Domoticz

Post 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...
FlyingDomotic
Posts: 463
Joined: Saturday 27 February 2016 0:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Script to send data to Domoticz

Post by FlyingDomotic »

If authentication is enabled, you may check that 127.0.0.1 is allowed to bypass it.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest