fhempy: rct_power (RCT-Power)

Begonnen von dominik, 10 Februar 2022, 20:20:12

Vorheriges Thema - Nächstes Thema

dominik

Genau, die Zeit zwischen 2 Abrufen meinte ich. Ok, bedeutet es kann immer nur ein Device eine Connection aufbauen?
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

marvin78

So ist es leider. RCT verspricht schon seit über einem Jahr ein Update der Firmware, mit der das Verhalten besser werden soll. Bisher kam nichts.

dominik

Neues Release:
- attr default_readings on/off
- attr error_reading on/off

So ist es vielleicht klarer und es bleiben alle Möglichkeiten vorhanden :)
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

chris_kmn


marvin78

Super. Nochmal danke, dass du mein Modul überfüssig gemacht hast. ;) Das hier klappt deutlich besser (was die Performance angeht, was zu mehr Konsistenz in den angezeigten Daten führt). Dass du die Ideen mit dem JSON Reading übernommen hast ist Klasse und das format nun drin ist auch.

dominik

Gerne :)

Stimmt, Format kann nun auch angegeben werden.

Ich werde mir dann noch WRITE ansehen, das sollte auch möglich sein. Gibt es in den Herstellerapps irgendwelche Werte die dort geschrieben werden?
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

chris_kmn

Auch von mir nochmal ein großes Lob und danke :)

In der App können z.B. folgene Werte geschrieben werden:

battery.soc_target
battery.soc_target_low
display_struct.brightness
display_struct.contrast
power_mng.battery_power
power_mng.soc_max
power_mng.soc_min
p_rec_lim[0]
p_rec_lim[1]
p_rec_lim[2]

Vielleicht nimmt man erstmal nur die beiden Display Werte. Das kann man leicht testen ohne den Inverter zu beeinflussen.




febus

Zitat von: dominik am 11 Februar 2022, 15:53:43
Wenn du einen Pi hast, dann mach einfach ein Standard Upgrade auf bullseye, dort ist Python 3.9 Standard. Ich empfehle keinesfalls Python manuell zu installieren.
Ok, das hat mich jetzt den Freitagabend gekostet, aber mein Pi ist auf dem aktuellen Stand und die Verbindung funktioniert. Danke dir!

Viele Grüße,
Marc

dominik

Zitat von: febus am 12 Februar 2022, 14:08:52
Ok, das hat mich jetzt den Freitagabend gekostet, aber mein Pi ist auf dem aktuellen Stand und die Verbindung funktioniert. Danke dir!

Ja, da muss man einmal durch ;) Glaub mir, der andere Weg mit manueller Installation verursacht sonst immer wieder Probleme. So hast du jetzt ein sauberes System.

Ad Write, ok, werde Mal brightness implementieren. Was für Werte kann man da schicken?
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

chris_kmn

In der Registry ist es als Byte Wert beschrieben:

0x29BDA75F
UINT8
UINT8
display_struct.brightness
Display brightness, [0..255]


dominik

Write für display brightness ist implementiert. Bitte mal ausprobieren, bin gespannt...
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

chris_kmn

Habs grad getestet aber klappt leider nicht :(

Auf den Events ist der Befehl zu sehen aber am Display ändert sich nichts. Ich schaue mal in deinen Code ob mir was auffällt

2022-02-12 20:13:15 fhempy RCTPower_AR power_grid_total: 755.20
2022-02-12 20:13:15 fhempy RCTPower_AR power_battery: 1.67
2022-02-12 20:13:15 fhempy RCTPower_AR overpow: 756.87
2022-02-12 20:13:21 fhempy RCTPower_AR display_brightness 255
2022-02-12 20:13:27 fhempy RCTPower_AR power_grid_total: 730.15
2022-02-12 20:13:27 fhempy RCTPower_AR power_battery: 1.65
2022-02-12 20:13:27 fhempy RCTPower_AR overpow: 731.8
2022-02-12 20:13:39 fhempy RCTPower_AR display_brightness 1
2022-02-12 20:13:39 fhempy RCTPower_AR power_grid_total: 759.75
2022-02-12 20:13:39 fhempy RCTPower_AR power_battery: 1.70
2022-02-12 20:13:39 fhempy RCTPower_AR overpow: 761.45

chris_kmn

#42
So wie es aussieht nutzt du eine andere Lib als die von rctclient, die ja beim lesen prima funktioniert.

Werden in deiner Lib die Daten auch nach diesem Workflow bearbeitet ?

Open a TCP socket to the device.
If payload is to be sent (write commands), use encode_value() to encode the data.
Craft a frame (using SendFrame or make_frame()) with the correct object ID and command set and, if required, include the payload.
Send the frame via a TCP socket to the device.
Read the response into a ReceiveFrame
Once complete, decode the response value using decode_value()
Repeat steps 2-6 as long as required.
Close the socket to the device.


Und das hier ist ein Beispiel von der rctclient Lib:
https://rctclient.readthedocs.io/en/latest/usage.html#sendframe


SendFrame

SendFrame is used to craft the byte stream used to send a request to the device. Uppon constructing the frame, it automatically crafts the byte stream, which is then available in the data property and can be sent to the device.

Note

The payload has to be encoded before passing it to SendFrame e.g. using encode_value().
The following example crafts a read command for the battery state of charge (battery.soc). The data that is to be sent via a network socket can be read from frame.data in the end:

>>> from rctclient.registry import REGISTRY as R
>>> from rctclient.frame import SendFrame
>>> from rctclient.types import Command
>>>
>>> oinfo = R.get_by_name('battery.soc')
>>> frame = SendFrame(command=Command.READ, id=oinfo.id)
>>> frame
<SendFrame(command=1, id=0x959930BF, payload=0x)>
>>> frame.data.hex()
'2b0104959930bf0d65'
make_frame

As discussed earlier, make_frame() is used internally by SendFrame. It basically behaves the same but does not require object instantiation and all that comes with it, but instead simply returns the generated bytes to be sent.

>>> from rctclient.registry import REGISTRY as R
>>> from rctclient.frame import make_frame
>>> from rctclient.types import Command
>>>
>>> oinfo = R.get_by_name('battery.soc')
>>> frame_data = make_frame(command=Command.READ, id=oinfo.id)
>>> frame_data.hex()
'2b0104959930bf0d65'

dominik

Nein, keine andere Lib, ist weiterhin rctclient.

Open a TCP socket to the device.
reader, writer = await open_connection(
                    host=self._hostname, port=self._port
                )

If payload is to be sent (write commands), use encode_value() to encode the data.
payload = encode_value(oinfo.request_data_type, value)

Craft a frame (using SendFrame or make_frame()) with the correct object ID and command set and, if required, include the payload.
send_command_frame = SendFrame(
            command=Command.WRITE, id=object_id, payload=payload
        )

Send the frame via a TCP socket to the device.
await writer.drain()
writer.write(send_command_frame.data)

Read the response into a ReceiveFrame
gleich wie bei READ

Once complete, decode the response value using decode_value()
gleich wie bei READ

Repeat steps 2-6 as long as required.
gleich wie bei READ

Close the socket to the device.
gleich wie bei READ

Einzige was man probieren könnte, das writer.drain() NACH writer.write(...) zu machen. Kannst du die beiden Zeilen mal im Code tauschen und ausprobieren?
sudo -u fhem bash
nano /opt/fhem/.local/lib/python3.9/site-packages/fhempy/lib/rct_power/api.py


Danach fhempy restart.
fhempy -  https://github.com/fhempy/fhempy: GoogleCast, Tuya, UPnP, Ring, EQ3BT, Nespresso, Xiaomi, Spotify, Object Detection, ...
Kaffeespende: https://paypal.me/todominik

chris_kmn