433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Moderator: leecollings

peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

Ok i will try that this evening.

Ah the if rfkey1 ==idx1 is looking to the idx1 more to the top where i fill in the idx of the light i try to switch on (idx7)

The import line i had before good. Why the as mqtt is away i don't know.
I will add this tonight also again.
But also with i had also no paho client.
But i will test it this evening.
I want to thank you for your help so far.
:D
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

Thanks

I still got this
2018-12-17 19:57:00.374 Error: EventSystem: Failed to execute python event script "Bridge-test"
2018-12-17 19:57:00.374 Error: EventSystem: Traceback (most recent call last):
2018-12-17 19:57:00.375 Error: EventSystem: File "<string>", line 10, in <module>
2018-12-17 19:57:00.375 Error: EventSystem: ImportError: No module named 'paho'

This is the file now


'<#!/usr/local/python3

'''
Python script to read rfkey number from Sonoff 433MHz RF Bridge
and control corresponding Domoticz.
This example only set up for 2 devices; extend by adding idx's in on_message.
(Not very pretty code!)
'''

import paho.mqtt.client as mqtt
import time
import json
import requests

### substitute your values here ###
broker_address="localhost" # port = 1883 by default
topic = "sonoffbridge"
dom_cmd = "http://127.0.0.1:8080/json.htm?type=com ... cmd=Toggle"
idx1 = 7
idx2 = 0


###################################

def on_message(client, userdata, message):
print ("message received " ,str(message.payload.decode("utf-8")))
jsonData = json.loads(message.payload)
rfkey = jsonData['RfReceived']['RfKey']
print ("rfkey")
if rfkey == 1:
idx = idx1
elif rfkey == 2:
idx = idx2
else:
return

url = dom_cmd + "&idx=" + str(idx)
print ("url")
r = requests.get(url)

#print "message topic=",message.topic
#print "message qos=",message.qos
#print "message retain flag=",message.retain

print("creating new instance")

client = mqtt.Client("P1") #create new instance
client.on_message=on_message #attach function to callback

print("connecting to broker")
client.connect(broker_address) #connect to broker

client.loop_start() #start the loop

print("Subscribing to topic ") + topic
client.subscribe("tele/" + topic + "/RESULT")

time.sleep(2) # wait
client.loop_forever() #loop forever
time.sleep(2) # wait
client.loop_forever() #loop forever>'
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

The paho is runnung.
From cmd it is working.
I think domoticz doesn't look in the right folder.
The python is here
/usr/lib/python2.7/dist-packages/

also the version 3 is in this folder.

So how can i tell the script where to look?
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by MikeF »

In my script, the ‘shebang’ (line 1) is

Code: Select all

#!/usr/bin/env python
(or python3, if you’re using that).

I think (not sure) that the use of env ensures that the right path is used to find installed modules (such as paho).
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

I had it also on python3 but it says the same.
Pfff I don't know anymore.
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

I changed the path to what you wrote.
The python is there as there is also the 3
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

Domoticz is going to be a dissapointing thing.
After christmas i am going to look how Homeassistant works.
I just cannot let a light switch on and off with a 433mhz 2 remote button.
The python on the raspbery is not accessable through home assistant.
In command screen it works.
So the python scripts in Domoticz are just not working.
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

So everybody a good newyear.
Today i decided to go back to my domoticz project.
I have made also a raspberry server with homeassistant.
This is working also with everything but also here no bridge.

Now i decided to focus on domoticz and go on with this.
I deinstaled all the python and autoremove for cleanup.
After this i installed python back and install pip and at last the paho-mqtt client.
From the command screen it seems to be working correct.
But when i start the scrypt again i got again paho client no module with this name.
How is this possible?
The first row i tried everything witn python and python3 and env python and env python3 but no result.

2019-01-06 18:29:00.418 Error: EventSystem: Failed to execute python event script "Bridge-test"
2019-01-06 18:29:00.419 Error: EventSystem: Traceback (most recent call last):
2019-01-06 18:29:00.419 Error: EventSystem: File "<string>", line 10, in <module>
2019-01-06 18:29:00.419 Error: EventSystem: ImportError: No module named 'paho'

#!/usr/bin/env python

'''
Python script to read rfkey number from Sonoff 433MHz RF Bridge
and control corresponding Domoticz.
This example only set up for 2 devices; extend by adding idx's in on_message.
(Not very pretty code!)
'''

import paho.mqtt.client as mqtt
import time
import json
import requests
omega001
Posts: 2
Joined: Saturday 09 March 2019 13:29
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by omega001 »

You can check this, maybe is this easiest
https://www.domoticz.com/forum/viewtopi ... 74&t=27284
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

Thanks i will try this.
peterdr
Posts: 26
Joined: Wednesday 28 November 2018 19:58
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: 433Mhz Touch Remote -> Sonoff RF Bridge -> Domoticz

Post by peterdr »

Ok thank you for the reactions.
@omega001
Now i have the bridge working with blocky.
The fun is coming back.
Thank you so much.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest