Eldat Easywave RXR09 Script

Python and python framework

Moderator: leecollings

WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Hi,

the response from RX09.py to plugin is handled in 'main listener loop' of serialReader.
The function reads the output of the serial (once you got the USB in place) and build up a char vector in myLine.
The function then determines if the serial has captured a transmission of a physical switch first (e.g. a Easywave remote) (line starts with REC...).
It will try to tie the unique code of the transmitter to a Domoticz idx (as described in the table devices.csv).
If found it will fire off a http call to Domoticz to inform Domoticz of the switch being applied.
If the content of myLine however is not of type REC.... the following 'else' part is invoked:
" # respons is not from physical switch
# write line to all clients
for elem in line:
for client in allClients:
client.send(elem)
"
This will transfer whatever is received from the serial port on the socket. The plugin will handle the response within Domoticz (as far as i know being only OK\r or ERROR\r)

Having said so without a USB in place the serialproxy RX09.py will wait indefinitely on respons from the serial port...
You could test by replacing the whole main listener loop by sending OK\r back via client.send(elem)

regards

WimR
tv46cfire
Posts: 6
Joined: Sunday 05 January 2020 17:15
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

Re: Eldat Easywave RXR09 Script

Post by tv46cfire »

Hi,
thanks for the complete good answer :D
I've got everything need !

All my problems come from python3, string vs Bytes, and other details. Now seems to work correctly.
Thank you for your original code which is very readable !

Regards.
tv46cfire
Posts: 6
Joined: Sunday 05 January 2020 17:15
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

Re: Eldat Easywave RXR09 Script

Post by tv46cfire »

Hello,
i've received my RX09-128, and it seems to work fine, but i've a dumb question.
REC work perfectly.
move shutter UP => REC,31fe34,A
move shutter DOWN => REC,31fe34,B
Stop shutter => REC,31fe34,C

But how to attribute serial '31fe34' to a "Position" used with TXP ?
When I use "RDP?,00" to check I obtain :
RDP,00,1d3200 OK

So serial "1d3200" is bind to Position 00.
How can I change this attribution ?

Regards
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Hi,

the USB will translate the TXP,00,A into a telegram with a unique code for 00 (apparently 1d3200). that's a fixed link in the USB key.
each hex 00 to 7F will have its unique identifier.
So each hex works the same as a separate physical switch (like the one you used when the USB received the code 31fe34) also there the unique code is hardcoded into the physical switch.
If you want the USB "00" to drive your screen/light/switch the same as the physical key you need to "pair" your new switch a.k.a the USB "00" with the screen/light/switch.

regards
tv46cfire
Posts: 6
Joined: Sunday 05 January 2020 17:15
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

Re: Eldat Easywave RXR09 Script

Post by tv46cfire »

Thanks.
So I need to access all shutter receiver to pair :( :( :(

Regards.
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Indeed

regards
tv46cfire
Posts: 6
Joined: Sunday 05 January 2020 17:15
Target OS: NAS (Synology & others)
Domoticz version: 4.10717
Location: France
Contact:

Re: Eldat Easywave RXR09 Script

Post by tv46cfire »

Hello,
after spending a lot time searching how to pair with my shutters (altron easywave), i've found the procedure.
1- shut down the shutter
2- push stop button for 5 to 10 secs, the shutter will open a little.
3- push button move up then move down.
4- the shutter will open/close a little.

5- use RX09 in serial with the channel you want to assign and request a move up -> TXP,00,A (for chan 0)
6- that's all check if up work (TXP,00,A), then down work (TXP,00,B) and then stop (TXP,00,C)

Regards.
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

This drawing summarizes the interaction between Easywave Devices (Recievers & Transmitters) the RX09.py and the Domoticz plugin

regards
Attachments
Easywavev2.png
Easywavev2.png (66.53 KiB) Viewed 2629 times
aeisenhuth
Posts: 46
Joined: Thursday 26 January 2017 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Homberg, Hessen, Germany
Contact:

Re: Eldat Easywave RXR09 Script

Post by aeisenhuth »

Hello WimR, your Easywave plugin has been working reliably for me for years, but my Raspberry ran out a few days ago. I now have a new Pi 4 with the latest Domoticz and Raspian, but the script no longer seems to run with the new versions of raspian and Domoticz. Do you have any idea what could be the reason? When I start a roller blind, there is an error in the log, I think the stick is not addressed. I would be very happy about a suggestion.

Best regards aeisenhuth
RaspberryPI Home Assistant with -> AppleHome, HUE, Osram, Ikea, Aqara, Xiaomi, Worx, SmartLife, AlphaESS, Meross, Viessmann, PhillipsTV, Shelly
RaspberryPI3 Domoticz -> EldatEasywave, Wunderground, MagicLight
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Hi Aeisenhuth,

missed the message.

i don't have a Pi4 yet.
Best to check:
- do the lines in the startup still work (the sudo lines). You could try to launch them from the PI4 console to check if the stick is recognized.
- if the USB stick is recognized does it still reside on the same terminal?

regards
aeisenhuth
Posts: 46
Joined: Thursday 26 January 2017 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Homberg, Hessen, Germany
Contact:

Re: Eldat Easywave RXR09 Script

Post by aeisenhuth »

Sorry for my late response. So the stick is properly recognized. BUS 001 DEVICE 004: ID 155a:1006 Silicon Labs USB Transceiver Easywave, when I switch something in the web interface I get the following message in the log of Domoticz:

2023-11-14 13:16:06.557 Eldat Easywave: Pushing 'onCommandCallback' on to queue
2023-11-14 13:16:06.596 Eldat Easywave: Processing 'onCommandCallback' message
2023-11-14 13:16:06.596 Eldat Easywave: Acquiring GIL for 'onCommandCallback'
2023-11-14 13:16:06.596 Eldat Easywave: Calling message handler 'onCommand' on 'module' type object.
2023-11-14 13:16:06.596 Eldat Easywave: onMessage called using socket params: 127.0.0.1 5331
2023-11-14 13:16:06.598 Eldat Easywave: Local context:
2023-11-14 13:16:06.599 Eldat Easywave: ----> 'Devices' '{1: <Domoticz.Device object at 0x717e18c0>, 2: <Domoticz.Device object at 0x705d7c20>, 3: <Domoticz.Device object at 0x705d74a0>, 4: <Domoticz.Device object at 0x705d7d40>, 5: <Domoticz.Device object at 0x705d7380>, 6: <Domoticz.Device object at 0x705d7ec0>, 7: <Domoticz.Device object at 0x705d7aa0>, 8: <Domoticz.Device object at 0x705d7f20>, 9: <Domoticz.Device object at 0x705d7f80>, 10: <Domoticz.Device object at 0x6ebd0020>, 11: <Domoticz.Device object at 0x6ebd0080>, 12: <Domoticz.Device object at 0x6ebd00e0>, 13: <Domoticz.Device object at 0x6ebd0140>, 14: <Domoticz.Device object at 0x6ebd01a0>, 15: <Domoticz.Device object at 0x6ebd0200>, 16: <Domoticz.Device object at 0x6ebd0260>, 17: <Domoticz.Device object at 0x6ebd02c0>, 18: <Domoticz.Device object at 0x6ebd0320>, 19: <Domoticz.Device object at 0x6ebd0380>, 20: <Domoticz.Device object at 0x6ebd03e0>, 21: <Domoticz.Device object at 0x6ebd0440>, 22: <Domoticz.Device object at 0x6ebd04a0>, 23: <Domoticz.Device object at 0x6ebd0500>, 24: <Domoticz.Device object at 0x6ebd0560>, 25: <Domoticz.Device object at 0x6ebd05c0>, 26: <Domoticz.Device object at 0x6ebd0620>, 27: <Domoticz.Device object at 0x6ebd0680>, 28: <Domoticz.Device object at 0x6ebd06e0>, 29: <Domoticz.Device object at 0x6ebd0740>, 30: <Domoticz.Device object at 0x6ebd07a0>, 31: <Domoticz.Device object at 0x6ebd0800>, 32: <Domoticz.Device object at 0x6ebd0860>, 33: <Domoticz.Device object at 0x6ebd08c0>, 34: <Domoticz.Device object at 0x6ebd0920>, 35: <Domoticz.Device object at 0x6ebd0980>, 36: <Domoticz.Device object at 0x6ebd09e0>, 37: <Domoticz.Device object at 0x6ebd0a40>, 38: <Domoticz.Device object at 0x6ebd0aa0>, 39: <Domoticz.Device object at 0x6ebd0b00>, 40: <Domoticz.Device object at 0x6ebd0b60>, 41: <Domoticz.Device object at 0x6ebd0bc0>, 42: <Domoticz.Device object at 0x6ebd0c20>, 43: <Domoticz.Device object at 0x6ebd0c80>, 44: <Domoticz.Device object at 0x6ebd0ce0>, 45: <Domoticz.Device object at 0x6ebd0d40>, 46: <Domoticz.Device object at 0x6ebd0da0>, 47: <Domoticz.Device object at 0x6ebd0e00>, 48: <Domoticz.Device object at 0x6ebd0e60>, 49: <Domoticz.Device object at 0x6ebd0ec0>, 50: <Domoticz.Device object at 0x6ebd0f20>, 51: <Domoticz.Device object at 0x6ebd0f80>, 52: <Domoticz.Device object at 0x6ebd3020>, 53: <Domoticz.Device object at 0x6ebd3080>, 54: <Domoticz.Device object at 0x6ebd30e0>, 55: <Domoticz.Device object at 0x6ebd3140>, 56: <Domoticz.Device object at 0x6ebd31a0>, 57: <Domoticz.Device object at 0x6ebd3200>, 58: <Domoticz.Device object at 0x6ebd3260>, 59: <Domoticz.Device object at 0x6ebd32c0>, 60: <Domoticz.Device object at 0x6ebd3320>, 61: <Domoticz.Device object at 0x6ebd3380>, 62: <Domoticz.Device object at 0x6ebd33e0>, 63: <Domoticz.Device object at 0x6ebd3440>, 64: <Domoticz.Device object at 0x6ebd34a0>}'
2023-11-14 13:16:06.599 Eldat Easywave: ----> 'Domoticz' '<module 'Domoticz' (built-in)>'
2023-11-14 13:16:06.599 Eldat Easywave: ----> 'Images' '{}'
2023-11-14 13:16:06.599 Eldat Easywave: ----> 'Parameters' '{'HardwareID': 2, 'HomeFolder': '/home/aeisenhuth/domoticz/plugins/Eldat_Easywave/', 'StartupFolder': '/home/aeisenhuth/domoticz/', 'UserDataFolder': '/home/aeisenhuth/domoticz/', 'WebRoot': '', 'Database': '/home/aeisenhuth/domoticz/domoticz.db', 'Language': 'de', 'Version': '0.4.0', 'Author': 'WimR', 'Name': 'Eldat Easywave', 'Address': '', 'Port': '0', 'SerialPort': '', 'Username': '', 'Password': '', 'Key': 'Easywave', 'Mode1': '64', 'Mode2': '127.0.0.1', 'Mode3': '5331', 'Mode4': '', 'Mode5': '', 'Mode6': 'Debug', 'DomoticzVersion': '2023.2 (build 15650)', 'DomoticzHash': '10dbd8d2e', 'DomoticzBuildTime': '2023-11-13 14:22:32'}'
2023-11-14 13:16:06.600 Eldat Easywave: ----> 'Settings' '{'DB_Version': '165', 'Title': 'Domoticz', 'Unique_ID': 'e1a5b05b-dc49-4ebe-9d99-98fb79d63bb6', 'LightHistoryDays': '30', 'MeterDividerEnergy': '1000', 'MeterDividerGas': '100', 'MeterDividerWater': '100', 'RandomTimerFrame': '15', 'ElectricVoltage': '230', 'CM113DisplayType': '0', '5MinuteHistoryDays': '1', 'SensorTimeout': '60', 'SensorTimeoutNotification': '0', 'UseAutoUpdate': '1', 'UseAutoBackup': '0', 'CostEnergy': '2149', 'CostEnergyT2': '2149', 'CostEnergyR1': '800', 'CostEnergyR2': '800', 'CostGas': '6218', 'CostWater': '16473', 'UseEmailInNotifications': '1', 'SendErrorNotifications': '0', 'EmailPort': '25', 'EmailAsAttachment': '0', 'DoorbellCommand': '0', 'SmartMeterType': '0', 'NotificationSensorInterval': '43200', 'NotificationSwitchInterval': '0', 'RemoteSharedPort': '6144', 'Language': 'de', 'DashboardType': '0', 'MobileType': '0', 'WindUnit': '0', 'TempUnit': '0', 'WeightUnit': '0', 'SecStatus': '0', 'SecOnDelay': '30', 'ReleaseChannel': '1', 'RaspCamParams': '-w 800 -h 600 -t 1', 'UVCParams': '-S80 -B128 -C128 -G80 -x800 -y600 -q100', 'AcceptNewHardware': '1', 'ZWavePollInterval': '60', 'ZWaveEnableDebug': '0', 'ZWaveNetworkKey': '0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10', 'ZWaveEnableNightlyNetworkHeal': '0', 'BatteryLowNotification': '0', 'AllowWidgetOrdering': '1', 'ActiveTimerPlan': '0', 'HideDisabledHardwareSensors': '1', 'EnableEventScriptSystem': '1', 'EventSystemLogFullURL': '1', 'DisableDzVentsSystem': '0', 'DzVentsLogLevel': '3', 'LogEventScriptTrigger': '1', 'WebTheme': 'default', 'FloorplanPopupDelay': '750', 'FloorplanFullscreenMode': '0', 'FloorplanAnimateZoom': '1', 'FloorplanShowSensorValues': '1', 'FloorplanShowSwitchValues': '0', 'FloorplanShowSceneNames': '1', 'FloorplanRoomColour': 'Blue', 'FloorplanActiveOpacity': '25', 'FloorplanInactiveOpacity': '5', 'TempHome': '20', 'TempAway': '15', 'TempComfort': '22.0', 'DegreeDaysBaseTemperature': '18.0', 'HTTPURL': 'aHR0cHM6Ly93d3cuc29tZWdhdGV3YXkuY29tL3B1c2h1cmwucGhwP3VzZXJuYW1lPSNGSUVMRDEmcGFzc3dvcmQ9I0ZJRUxEMiZhcGlrZXk9I0ZJRUxEMyZmcm9tPSNGSUVMRDQmdG89I1RPJm1lc3NhZ2U9I01FU1NBR0U=', 'HTTPPostContentType': 'YXBwbGljYXRpb24vanNvbg==', 'ShowUpdateEffect': '0', 'ShortLogInterval': '5', 'ShortLogAddOnlyNewValues': '0', 'SendErrorsAsNotification': '0', 'IFTTTEnabled': '0', 'EmailEnabled': '1', 'MaxElectricPower': '6000', 'Domoticz_Version': '2023.2 (build 15650)', 'OneWireSensorPollPeriod': '0', 'OneWireSwitchPollPeriod': '0', 'IFTTTAPI': '0', 'Location': '51.0357;9.41577', 'AllowPlainBasicAuth': '0', 'WebLocalNetworks': '0', 'SecPassword': 'd41d8cd98f00b204e9800998ecf8427e', 'ProtectionPassword': 'd41d8cd98f00b204e9800998ecf8427e', 'ClickatellEnabled': '0', 'ClickatellAPI': '0', 'ClickatellFrom': '0', 'ClickatellTo': '0', 'EmailFrom': '0', 'EmailServer': '0', 'EmailTo': '0', 'EmailPassword': '0', 'EmailUsername': '0', 'FCMEnabled': '0', 'HTTPEnabled': '0', 'HTTPField1': '0', 'HTTPField2': '0', 'HTTPField3': '0', 'HTTPField4': '0', 'HTTPPostData': '0', 'HTTPPostHeaders': '0', 'HTTPTo': '0', 'KodiIPAddress': '224.0.0.1', 'KodiEnabled': '0', 'KodiPort': '9777', 'KodiTimeToLive': '5', 'LmsPlayerMac': '0', 'LmsDuration': '5', 'LmsEnabled': '0', 'ProwlAPI': '0', 'ProwlEnabled': '0', 'PushALotAPI': '0', 'PushALotEnabled': '0', 'PushbulletAPI': '0', 'PushbulletEnabled': '0', 'PushoverAPI': '0', 'PushoverUser': '0', 'PushoverEnabled': '0', 'PushsaferAPI': '0', 'PushsaferImage': '0', 'PushsaferEnabled': '0', 'TelegramAPI': '0', 'TelegramChat': '0', 'TelegramEnabled': '0'}'
2023-11-14 13:16:06.600 Eldat Easywave: ----> 'socket' '<module 'socket' from '/usr/lib/python3.9/socket.py'>'
2023-11-14 13:16:06.600 Eldat Easywave: ----> 'sys' '<module 'sys' (built-in)>'
2023-11-14 13:16:06.600 Eldat Easywave: ----> 'time' '<module 'time' (built-in)>'
2023-11-14 13:16:06.600 Eldat Easywave: Acquiring GIL for 'onCommandCallback'
2023-11-14 13:16:06.556 Status: User: admin (IP: 192.168.178.134) initiated a switch command (2/Beschattung_Esszimmer_EG/Close)
2023-11-14 13:16:06.597 Error: Eldat Easywave: Call to function 'onCommand' failed, exception details:
2023-11-14 13:16:06.597 Error: Eldat Easywave: Traceback (most recent call last):
2023-11-14 13:16:06.597 Error: Eldat Easywave: File "/home/aeisenhuth/domoticz/plugins/Eldat_Easywave/plugin.py", line 114, in onCommand
2023-11-14 13:16:06.597 Error: Eldat Easywave: sock.connect(server_address)
2023-11-14 13:16:06.598 Error: Eldat Easywave: ConnectionRefusedError: [Errno 111] Connection refused

2023-11-14 13:16:09.006 Eldat Easywave: Pushing 'onHeartbeatCallback' on to queue
2023-11-14 13:16:09.056 Eldat Easywave: Processing 'onHeartbeatCallback' message
2023-11-14 13:16:09.056 Eldat Easywave: Acquiring GIL for 'onHeartbeatCallback'
2023-11-14 13:16:09.056 Eldat Easywave: Calling message handler 'onHeartbeat' on 'module' type object.
2023-11-14 13:16:09.056 Eldat Easywave: Acquiring GIL for 'onHeartbeatCallback'
2023-11-14 13:16:19.024 Eldat Easywave: Pushing 'onHeartbeatCallback' on to queue

I reinstalled the PI, then domoticz, then the scripts. SOnst is not on the PI. The stick is connected to the PI via USB. I hope someone can help me. I don`t hab a serproxy.log on my raspberry?

Best regards
AEisenhuth
RaspberryPI Home Assistant with -> AppleHome, HUE, Osram, Ikea, Aqara, Xiaomi, Worx, SmartLife, AlphaESS, Meross, Viessmann, PhillipsTV, Shelly
RaspberryPI3 Domoticz -> EldatEasywave, Wunderground, MagicLight
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Hi aeisenhuth,
if you've got no serproxy.log on the raspberry could you check if the serproxy is running?
You can test by launching directly:
python /home/pi/project/python_programs/rx09.py /dev/ttyUSB0 5331 &

Check maybe if the code is still compatible with the Python 3,9 you seem to be runnning.
Another possibility: I suspect that the stick is not recognized on ttyUSB0 but another ttyUSBx. Your log mention device 4

In order for it to start at boot You should have this line in rc.local (with x replaced by the correct tty)

python /home/pi/project/python_programs/rx09.py /dev/ttyUSBx 5331 &

regards
aeisenhuth
Posts: 46
Joined: Thursday 26 January 2017 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Homberg, Hessen, Germany
Contact:

Re: Eldat Easywave RXR09 Script

Post by aeisenhuth »

Thanks for the tips. I'll test it tomorrow and report back.

Best Regards
A. Eisenhuth
RaspberryPI Home Assistant with -> AppleHome, HUE, Osram, Ikea, Aqara, Xiaomi, Worx, SmartLife, AlphaESS, Meross, Viessmann, PhillipsTV, Shelly
RaspberryPI3 Domoticz -> EldatEasywave, Wunderground, MagicLight
aeisenhuth
Posts: 46
Joined: Thursday 26 January 2017 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Homberg, Hessen, Germany
Contact:

Re: Eldat Easywave RXR09 Script

Post by aeisenhuth »

When i test directly in Putty:
python /home/pi/project/python_programs/rx09.py /dev/ttyUSB0 5331 &

then i became:
aeisenhuth@domoticz:~ $ python /home/aeisenhuth/project/python_programs/rx09.py /dev/ttyUSB0 5331 &
[1] 2096
aeisenhuth@domoticz:~ $ File "/home/aeisenhuth/project/python_programs/rx09.py", line 82
line.append(out)
TabError: inconsistent use of tabs and spaces in indentation
RaspberryPI Home Assistant with -> AppleHome, HUE, Osram, Ikea, Aqara, Xiaomi, Worx, SmartLife, AlphaESS, Meross, Viessmann, PhillipsTV, Shelly
RaspberryPI3 Domoticz -> EldatEasywave, Wunderground, MagicLight
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Hi aeisenhuth,

youre Python seems to be a bit more picky on the usage of spaces or tab in the code in order to indent.
I've added the code with all spaces replaced by tabs.

Code: Select all

# Date: 2018 01 12 Original version
#       2018 02 28 Added read csv with link: switch id TO domoticz idx
#		  Read serial line and add to log as 'respons'
#       2018 03 16 Added 'C' telegram mapped to 'Stop' (for devices Venitian Blinds EU)
#	       19 Added Dict for Commands
#		  Made path to devices.csv relative
#		  Added counter for devices table
#	       30 Added different behaviour for Blinds. SwitchType will be checked first
#
from socket import * 
from threading import Thread
import logging
import serial
import time
import sys
import os
import csv
import json, urllib, urllib2

ser = None

allClients = []
BUFSIZ = 1024
serialDevice = None


def serialReader():
  global ser
  global allClients
  global serialDevice
  global domoticzIP
  global domoticzPort
  global pairingFile

  line = []
  oldLine = ''
  oldTime = time.time()
  allDevices = {}
  CommandMap = {'A':'On','B':'Off','C':'Stop','D':'Off'}
  CommandMapBlind = {'A':'Off','B':'On','C':'Stop','D':'Off'}

  while 1:
    try:
      # configure the serial connections (the parameters differs on the device you are connecting to)
      ser = serial.Serial(
	port=serialDevice,
	baudrate=57600,
	parity=serial.PARITY_NONE,
	stopbits=serial.STOPBITS_ONE,
	bytesize=serial.EIGHTBITS
      )

      ser.isOpen()
      logging.info('Serial port opened %s', ser)

      # load device table from csv file
      logging.info('Device table being loaded in dictionnary.')
      ifile = open(pairingFile, "rU")
      logging.info('Device table being opened.')
      reader = csv.reader(ifile, delimiter=";")
      allDevices = dict([(row[0],row[1]) for row in reader])
      ifile.close()
      logging.info('Device table being closed.')
      logging.info('Device table loaded in dictionnary. Number of devices loaded: %d ' % len(allDevices))

      # main listener loop
      while 1:
	out = ser.read(1)
	line.append(out)
	# wait till '\r' as end of line char
	if out == '\r':
		myLine = ''.join(line)
		myTime = time.time()
		logging.info('Serial respons : %s', myLine)
		# if myLine starts with REC :split line use second part as key in dict and lauch json call
		if myLine[0:3] == 'REC':
		   if allDevices.get(myLine[4:10]) is None:
		      # transmitter not in devices.csv
		      logging.info('Warning : unknown physical RF transmitter: %s  Please add to device table with corresponding idx', myLine[4:10])
		   else:
      			# Check with Domoticz what kind of switch we are dealing with
		   	result_load = json.load(urllib2.urlopen("http://%s:%s/json.htm?type=devices&rid=%s" % ( domoticzIP, domoticzPort, allDevices.get(myLine[4:10])), timeout=5))
			if result_load["result"][0]["SwitchTypeVal"] is None:
			  logging.info("Warning : Key :  %s is linked to idx: %s but its not a Switch "%  (myLine[4:10],allDevices.get(myLine[4:10])))
			else:
			 if result_load["result"][0]["SwitchTypeVal"] == 15:
	       		    myCommand = CommandMapBlind.get(myLine[11])
			 else:
	       		    myCommand = CommandMap.get(myLine[11])
 	  		 # known physical RF transmitter linked to switch
  			 if myCommand is None:
			    logging.info('Warning : unknown Command from physical transmitter: ' + myLine[11])
		   	 else:
 			    logging.info('Key : ' + myLine[4:10] + ' Mapped to : ' +  allDevices.get(myLine[4:10]) + ' Telegram : ' + myLine[11] + ' mapped to Command : ' + myCommand)
		   	    # switches may bounce and emit rapidly 2 to 5 times the same command: debounce by comparing content and time lapse (more than 1 sec apart)
			    if myLine <> oldLine or myTime - oldTime > 1: 
		       		# transfer received command to Domoticz
			       	result_load = json.load(urllib2.urlopen("http://%s:%s/json.htm?type=command&param=switchlight&idx=%s&switchcmd=%s&level=0" % (domoticzIP, domoticzPort, allDevices.get(myLine[4:10]), myCommand), timeout=5))
		       		logging.info('Respons domoticz : %s', str(result_load))
				# arm debounce mechanism
		       		oldTime = myTime
		       		oldLine = myLine
		else:
		   # respons is not from physical switch
		   # write line to all clients
		   for elem in line:
		       for client in allClients:
 		  	   client.send(elem)
		# Clear line
		line = []
    except:
      # Wait a while then try again
      logging.debug('Error on serial port')
      if ser is not None:
	ser.close()
      ser = None
      time.sleep(10)

def handler(clientsock,addr):
  global ser
  global allClients
  logging.info('connected from: %s', addr)
  allClients.append(clientsock)
  while 1:
    data = clientsock.recv(BUFSIZ)
    if not data: 
      break 
    if not (ser is None):
      ser.write(data)
      logging.info('Message received: %s ', data)
  logging.info('disconnected from: %s', addr)
  allClients.remove(clientsock)
  clientsock.close()

def mainProgram():
  global serialDevice
  global port
  global domoticzIP
  global domoticzPort
  global pairingFile

  if len(sys.argv)>=8 and sys.argv[1] == '-p':
    writePidFile(sys.argv[2])
    del sys.argv[2]
    del sys.argv[1]
  if len(sys.argv) != 6:
    print ('usage: ' + sys.argv[0] + ' device port domoticzIP domoticzPort pairingFile')
    exit()

  print ('Logfile: /tmp/SerProxy.Log')
  logging.basicConfig(filename='/tmp/SerProxy.Log', filemode='w', format='%(asctime)s %(levelname)s:%(message)s', level=logging.DEBUG)

  serialDevice=sys.argv[1]
  port=int(sys.argv[2])
  domoticzIP=sys.argv[3]
  domoticzPort=sys.argv[4]
  pairingFile=sys.argv[5]

  print ('Version Serial Proxy: RX09v20180330')
  print ('Serial Device: ' + sys.argv[1])
  print ('Serial Port: ' + sys.argv[2])
  print ('Domoticz IP: ' + sys.argv[3])
  print ('Domoticz Port: ' + sys.argv[4])
  print ('Pairing File: ' + sys.argv[5])

  logging.info('Version Serial Proxy: RX09v20180330')
  logging.info('Serial Device: ' + sys.argv[1])
  logging.info('Serial Port: ' + sys.argv[2])  
  logging.info('Domoticz IP: ' + sys.argv[3])
  logging.info('Domoticz Port: ' + sys.argv[4])
  logging.info('Pairing File: ' + sys.argv[5])

  Thread(target=serialReader).start()

  ser = None
  allClients = []

  listenAddr = ('', port)
  try:
    serversock = socket(AF_INET, SOCK_STREAM)
    serversock.bind(listenAddr)
    serversock.listen(2)
    logging.info('waiting for connection')

    while 1:
      clientsock, addr = serversock.accept()
      Thread(target=handler, args=(clientsock, addr)).start()
  except KeyboardInterrupt:
    if not ser is None:
      ser.close()
    os._exit(0)

def writePidFile(pidfile):
    pid = str(os.getpid())
    f = open(pidfile, 'w')
    f.write(pid)
    f.close()

if __name__=='__main__':
    mainProgram()


Can you put this as rx09.py and retry?

regards
aeisenhuth
Posts: 46
Joined: Thursday 26 January 2017 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Homberg, Hessen, Germany
Contact:

Re: Eldat Easywave RXR09 Script

Post by aeisenhuth »

Dear WimR, thank you very much for your elaborate help. I have rx09.py replaced the file, but I'm still getting an error message. I'm still going crazy. Could it be due to the current pyhton 3.9 which is installed at the PI.

2023-11-25 17:58:05.746 Status: User: admin (IP: 2003:db:d700:3e00:ad1a:840b:2f5:dd7e) initiated a switch command (1/Beschattung_Arbeitszimmer/Open)
2023-11-25 17:58:05.776 Error: Eldat Easywave: Call to function 'onCommand' failed, exception details:
2023-11-25 17:58:05.777 Error: Eldat Easywave: Traceback (most recent call last):
2023-11-25 17:58:05.777 Error: Eldat Easywave: File "/home/aeisenhuth/domoticz/plugins/Eldat_Easywave/plugin.py", line 114, in onCommand
2023-11-25 17:58:05.777 Error: Eldat Easywave: sock.connect(server_address)
2023-11-25 17:58:05.777 Error: Eldat Easywave: ConnectionRefusedError: [Errno 111] Connection refused
Attachments
putty.jpg
putty.jpg (144.17 KiB) Viewed 2030 times
RaspberryPI Home Assistant with -> AppleHome, HUE, Osram, Ikea, Aqara, Xiaomi, Worx, SmartLife, AlphaESS, Meross, Viessmann, PhillipsTV, Shelly
RaspberryPI3 Domoticz -> EldatEasywave, Wunderground, MagicLight
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Hi A.Eisenhuth,

as far as i can see the transceiver is marked as device 4.
Can you check if in /dev you've got a ttyUSB4 ?
If so change the line into:

python /home/aisenhuth/project/python_programs/rx09.py /dev/ttyUSB4 5331
you should get some message on the console


regards
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

Included a version with spaces instead of tabs. This shoudl work under Python 3.8

Code: Select all

# Date: 2018 01 12 Original version
#       2018 02 28 Added read csv with link: switch id TO domoticz idx
#                  Read serial line and add to log as 'respons'
#       2018 03 16 Added 'C' telegram mapped to 'Stop' (for devices Venitian Blinds EU)
#               19 Added Dict for Commands
#                  Made path to devices.csv relative
#                  Added counter for devices table
#               30 Added different behaviour for Blinds. SwitchType will be checked first
#
from socket import * 
from threading import Thread
import logging
import serial
import time
import sys
import os
import csv
import json, urllib, urllib2

ser = None

allClients = []
BUFSIZ = 1024
serialDevice = None


def serialReader():
  global ser
  global allClients
  global serialDevice
  global domoticzIP
  global domoticzPort
  global pairingFile

  line = []
  oldLine = ''
  oldTime = time.time()
  allDevices = {}
  CommandMap = {'A':'On','B':'Off','C':'Stop','D':'Off'}
  CommandMapBlind = {'A':'Off','B':'On','C':'Stop','D':'Off'}

  while 1:
    try:
      # configure the serial connections (the parameters differs on the device you are connecting to)
      ser = serial.Serial(
        port=serialDevice,
        baudrate=57600,
        parity=serial.PARITY_NONE,
        stopbits=serial.STOPBITS_ONE,
        bytesize=serial.EIGHTBITS
      )

      ser.isOpen()
      logging.info('Serial port opened %s', ser)

      # load device table from csv file
      logging.info('Device table being loaded in dictionnary.')
      ifile = open(pairingFile, "rU")
      logging.info('Device table being opened.')
      reader = csv.reader(ifile, delimiter=";")
      allDevices = dict([(row[0],row[1]) for row in reader])
      ifile.close()
      logging.info('Device table being closed.')
      logging.info('Device table loaded in dictionnary. Number of devices loaded: %d ' % len(allDevices))

      # main listener loop
      while 1:
        out = ser.read(1)
        line.append(out)
        # wait till '\r' as end of line char
        if out == '\r':
                myLine = ''.join(line)
                myTime = time.time()
                logging.info('Serial respons : %s', myLine)
                # if myLine starts with REC :split line use second part as key in dict and lauch json call
                if myLine[0:3] == 'REC':
                   if allDevices.get(myLine[4:10]) is None:
                      # transmitter not in devices.csv
                      logging.info('Warning : unknown physical RF transmitter: %s  Please add to device table with corresponding idx', myLine[4:10])
                   else:
                           # Check with Domoticz what kind of switch we are dealing with
                           result_load = json.load(urllib2.urlopen("http://%s:%s/json.htm?type=devices&rid=%s" % ( domoticzIP, domoticzPort, allDevices.get(myLine[4:10])), timeout=5))
                           if result_load["result"][0]["SwitchTypeVal"] is None:
                              logging.info("Warning : Key :  %s is linked to idx: %s but its not a Switch "%  (myLine[4:10],allDevices.get(myLine[4:10])))
                           else:
                              if result_load["result"][0]["SwitchTypeVal"] == 15:
                                 myCommand = CommandMapBlind.get(myLine[11])
                              else:
                                   myCommand = CommandMap.get(myLine[11])
                           # known physical RF transmitter linked to switch
                           if myCommand is None:
                              logging.info('Warning : unknown Command from physical transmitter: ' + myLine[11])
                           else:
                              logging.info('Key : ' + myLine[4:10] + ' Mapped to : ' +  allDevices.get(myLine[4:10]) + ' Telegram : ' + myLine[11] + ' mapped to Command : ' + myCommand)
                              # switches may bounce and emit rapidly 2 to 5 times the same command: debounce by comparing content and time lapse (more than 1 sec apart)
                              if myLine != oldLine or myTime - oldTime > 1: 
                                 # transfer received command to Domoticz
                                 result_load = json.load(urllib2.urlopen("http://%s:%s/json.htm?type=command&param=switchlight&idx=%s&switchcmd=%s&level=0" % (domoticzIP, domoticzPort, allDevices.get(myLine[4:10]), myCommand), timeout=5))
                                 logging.info('Respons domoticz : %s', str(result_load))
                                 # arm debounce mechanism
                                 oldTime = myTime
                                 oldLine = myLine
                else:
                   # respons is not from physical switch
                   # write line to all clients
                   for elem in line:
                       for client in allClients:
                              client.send(elem)
                # Clear line
                line = []
    except:
      # Wait a while then try again
      logging.debug('Error on serial port')
      if ser is not None:
       ser.close()
      ser = None
      time.sleep(10)

def handler(clientsock,addr):
  global ser
  global allClients
  logging.info('connected from: %s', addr)
  allClients.append(clientsock)
  while 1:
    data = clientsock.recv(BUFSIZ)
    if not data: 
      break 
    if not (ser is None):
      ser.write(data)
      logging.info('Message received: %s ', data)
  logging.info('disconnected from: %s', addr)
  allClients.remove(clientsock)
  clientsock.close()

def mainProgram():
  global serialDevice
  global port
  global domoticzIP
  global domoticzPort
  global pairingFile

  if len(sys.argv)>=8 and sys.argv[1] == '-p':
    writePidFile(sys.argv[2])
    del sys.argv[2]
    del sys.argv[1]
  if len(sys.argv) != 6:
    print ('usage: ' + sys.argv[0] + ' device port domoticzIP domoticzPort pairingFile')
    exit()

  print ('Logfile: /tmp/SerProxy.Log')
  logging.basicConfig(filename='/tmp/SerProxy.Log', filemode='w', format='%(asctime)s %(levelname)s:%(message)s', level=logging.DEBUG)

  serialDevice=sys.argv[1]
  port=int(sys.argv[2])
  domoticzIP=sys.argv[3]
  domoticzPort=sys.argv[4]
  pairingFile=sys.argv[5]

  print ('Version Serial Proxy: RX09v20180330')
  print ('Serial Device: ' + sys.argv[1])
  print ('Serial Port: ' + sys.argv[2])
  print ('Domoticz IP: ' + sys.argv[3])
  print ('Domoticz Port: ' + sys.argv[4])
  print ('Pairing File: ' + sys.argv[5])

  logging.info('Version Serial Proxy: RX09v20180330')
  logging.info('Serial Device: ' + sys.argv[1])
  logging.info('Serial Port: ' + sys.argv[2])  
  logging.info('Domoticz IP: ' + sys.argv[3])
  logging.info('Domoticz Port: ' + sys.argv[4])
  logging.info('Pairing File: ' + sys.argv[5])

  Thread(target=serialReader).start()

  ser = None
  allClients = []

  listenAddr = ('', port)
  try:
    serversock = socket(AF_INET, SOCK_STREAM)
    serversock.bind(listenAddr)
    serversock.listen(2)
    logging.info('waiting for connection')

    while 1:
      clientsock, addr = serversock.accept()
      Thread(target=handler, args=(clientsock, addr)).start()
  except KeyboardInterrupt:
    if not ser is None:
      ser.close()
    os._exit(0)

def writePidFile(pidfile):
    pid = str(os.getpid())
    f = open(pidfile, 'w')
    f.write(pid)
    f.close()

if __name__=='__main__':
    mainProgram()


aeisenhuth
Posts: 46
Joined: Thursday 26 January 2017 21:07
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Homberg, Hessen, Germany
Contact:

Re: Eldat Easywave RXR09 Script

Post by aeisenhuth »

When i try in the putty console: python /home/aisenhuth/project/python_programs/rx09.py /dev/ttyUSB4 5331
or python /home/aisenhuth/project/python_programs/rx09.py /dev/ttyUSB0 5331
i get this message on the console: usage: rx09.py device port domoticzIP domoticzPort pairingFile

But nothing happens
RaspberryPI Home Assistant with -> AppleHome, HUE, Osram, Ikea, Aqara, Xiaomi, Worx, SmartLife, AlphaESS, Meross, Viessmann, PhillipsTV, Shelly
RaspberryPI3 Domoticz -> EldatEasywave, Wunderground, MagicLight
WimR
Posts: 46
Joined: Saturday 03 February 2018 17:18
Target OS: NAS (Synology & others)
Domoticz version: 2020.2
Location: Belgium
Contact:

Re: Eldat Easywave RXR09 Script

Post by WimR »

i'll look into it this evening
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest