-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date and time #112
Comments
That should be possible with the new sensor overrides - see the docs add the sensor as import attr
from sunsynk.rwsensors import RWSensor, ResolveType
from sunsynk.sensors import RegType, ValType, SensorDefinitions
SENSORS = SensorDefinitions()
@attr.define(slots=True, eq=False)
class TimeRWSensor(RWSensor):
"""Read & write time sensor."""
def value_to_reg(self, value: ValType, resolve: ResolveType) -> RegType:
"""Get the reg value from a display value."""
raise NotImplementedError()
def reg_to_value(self, regs: RegType) -> ValType:
"""Decode the register."""
y = ((regs[0] & 0xFF00) >> 8) + 2000
m = regs[0] & 0xFF
d = (regs[1] & 0xFF00) >> 8
h = regs[1] & 0xFF
mn = (regs[2] & 0xFF00) >> 8
s = regs[2] & 0xFF
return f"{y}-{m:02}-{d:02} {h}:{mn:02}:{s:02}"
SENSORS += TimeRWSensor((22, 23, 24), "Date", "") |
Ok i'll try and comment, thanks! :( Sorry I'm reading the documents but I have no idea of programming beyond copy and paste and I don't quite understand what I should do, pasting your example I get the sensor as reading. |
This sensor only reads the current time. You probably only ever want to set this to the current system time? |
Yes, I would like to be able to update the current system time through a writable sensor so I could automate that every month, for example, it will be synchronized with the time of the home assistant |
I've expanded on the write concept a bit here - https://kellerza.github.io/sunsynk/reference/mysensors#time-sensor But still not 100% compete&tested, maybe you can test it and see if it works? |
Hello, I just tried it and it gives me an error. I have replaced the previous code with the new one, I paste the output
And my sensores.py: import attr
import re
# from sunsynk import AMPS, CELSIUS, KWH, VOLT, WATT
from sunsynk.rwsensors import RWSensor, ResolveType
from sunsynk.sensors import RegType, ValType, SensorDefinitions
SENSORS = SensorDefinitions()
@attr.define(slots=True, eq=False)
class SystemTimeRWSensor(RWSensor):
"""Read & write time sensor."""
def value_to_reg(self, value: ValType, resolve: ResolveType) -> RegType:
"""Get the reg value from a display value."""
redt = re.compile(r"(2\d{3})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})")
match = redt.fullmatch(value)
if not match:
raise ValueError("Invalid datetime {value}")
y, m, d = int(match.group(1)) - 2000, int(match.group(2)), int(match.group(3))
h, mn, s = int(match.group(4)), int(match.group(5)), int(match.group(6))
regs = (
(y << 8) + m,
(d << 8) + h,
(mn << 8) + s,
)
raise ValueError(f"{y}-{m:02}-{d:02} {h}:{mn:02}:{s:02} ==> {regs}")
return regs
def reg_to_value(self, regs: RegType) -> ValType:
"""Decode the register."""
y = ((regs[0] & 0xFF00) >> 8) + 2000
m = regs[0] & 0xFF
d = (regs[1] & 0xFF00) >> 8
h = regs[1] & 0xFF
mn = (regs[2] & 0xFF00) >> 8
s = regs[2] & 0xFF
return f"{y}-{m:02}-{d:02} {h}:{mn:02}:{s:02}"
SENSORS += SystemTimeRWSensor((22, 23, 24), "Date", unit="")
from sunsynk import AMPS, CELSIUS, KWH, VOLT, WATT
from sunsynk.rwsensors import NumberRWSensor, SelectRWSensor, TimeRWSensor
from sunsynk.sensors import (
MathSensor,
Sensor,
SensorDefinitions,
TempSensor,
)
SENSORS += TimeRWSensor((22, 23, 24), "Date", "")
SENSORS += NumberRWSensor(293, "Grid Peak Shaving Power", WATT, min=0, max=16000)
SENSORS += Sensor(164, "Inverter current", AMPS, 0.01),
SENSORS += Sensor(192, "Load frequency", "Hz", 0.01),
SENSORS += SelectRWSensor(
247, "Solar Sell", options={0: "No", 1: "Yes"}
) |
This line was for the previous sensor and should be removed (TieRWSensor is the class of the system settings time) SENSORS += TimeRWSensor((22, 23, 24), "Date", "") |
ok now it does not give errors anymore, it is grouped as a configuration sensor inside the inverter device but there is no way to configure it, it does not allow writing, it seems like a read-only sensor. |
Writing at the moment will only print something in the log. If you are happy with what you see in the log you can comment out/delete the raise ValueError(f"{y}-{m:02}-{d:02} {h}:{mn:02}:{s:02} ==> {regs}")
return regs If the date you see in the log does not reflect the date you entered, it's better to fine-tune it a bit more before writing completely incorrect values |
Hello, I'm not sure I understand you, I've restarted the plugin but I don't see anything regarding the date sensor or the sunsynk plugin itself in the homeassistant log |
Can you try the |
ok should i remove any old references in the mysensor.py file? |
I have left it like this, and it seems to work, I will do more tests today and I will confirm but a priori it seems that it writes the records well from sunsynk import AMPS, CELSIUS, KWH, VOLT, WATT import attr from sunsynk import AMPS, CELSIUS, KWH, VOLT, WATTfrom sunsynk.rwsensors import RWSensor, ResolveType SENSORS = SensorDefinitions() SENSORS += NumberRWSensor(293, "Grid Peak Shaving Power", WATT, min=0, max=16000) SENSORS += SelectRWSensor( edit: it writes the values correctly although it does not load new time data until the addon is restarted, if I put :now after the sensor name it gives me an error |
date_time is part of the library and you do not need it in your mysensors.py file anymore not sure about the read frequency/ why :now does not work |
hi again it seems like the reading updates every 4-5 minutes otherwise it works fine. should the :now? modifier work? Another thing that I see, in the definitions file at the top I see that there is SystemTimeRwSensor and also TimeRwSensor. it's correct like this? |
Hi, I'm writing here again because I just realized that the plugin doesn't write the values of the date and time, I guess since some update but I haven't looked at it for a long time. the plugin log throws me this message: |
Do you still have this defined in You should remove it from mysensors. And ONLY add it to your config:
The log format from the sensors in the official library is different, so I expect you still use the example above - https://github.com/kellerza/sunsynk/blob/main/sunsynk/rwsensors.py#L155 |
This is mysensors.py from sunsynk import AMPS, CELSIUS, KWH, VOLT, WATT import attr from sunsynk import AMPS, CELSIUS, KWH, VOLT, WATTfrom sunsynk.rwsensors import RWSensor, ResolveType SENSORS = SensorDefinitions() SENSORS += NumberRWSensor(293, "Grid Peak Shaving Power", WATT, min=0, max=16000) SENSORS += Sensor(192, "Load frequency", "Hz", 0.01), SENSORS += SelectRWSensor( |
Another turbo energy user from Spain has confirmed that the same thing is happening to him too. Is it better if we open a new error or does it not matter? |
Hi, same problem here...I'm not able to write the data_time sensor. It always goes back to it previous state. |
Can you share a log snippet with debug enabled while writing? |
Hello, I have deactivated the rest of the sensors because otherwise it was very difficult for me to take the date_time records, I don't know if the log file is saved in its entirety in any file. |
It seems that now it gives more information, I'll paste another log to see if it helps |
Hello, good morning, with the new version it keeps failing, it seems that it is trying to write the value but it can't because after a minute the previous time appears again. |
It seems like it is not possible to write to these registers. At least all the attempts on my inverter failed as well. Maybe this is something you can ask Sunsynk? Have you ever seen it done from other apps? |
Have you unckecked time sync function ?
Le mer. 13 sept. 2023 à 09:46, Johann Kellerman ***@***.***>
a écrit :
… It seems like it is not possible to write to these registers. At least all
the attempts on my inverter failed as well.
Maybe this is something you can ask Sunsynk?
Have you ever seen it done from other apps?
—
Reply to this email directly, view it on GitHub
<#112 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AYDJ6M5YUWA7HQNK6QXPVGDX2FQDZANCNFSM6AAAAAAWCA6HIU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Yes i have this unchecked. |
Does anyone have an automation in home assistant to update the date and time that they would be willing to share? I was able to update mine manually today, but it would be nice to automate it to happen once a week or so. FYI, I noticed that once I had updated the time on my main inverter, the other two inverters running in parallel also updated to match the main inverter.... I always thought they needed to be adjusted separately. :) |
Unfortunately that doesn't work for my Deye sun-8k (not automation, I can't change the value on inverter even through UI)
|
Hi. Adding date_time as a sensor worked perfectly for me. It's a requirement to be able to do this in the 16kw inverter set up if you want to write via the wifi dongle port as opposed to the rs485. The inverter had lost track of time quite significantly when off wifi. Inputting the correct value via home assistant text box fixed this. |
Sorry, but do I understand correctly that you're using inverter's rs232 port (wifi dongle port) to read/write data as through rs485? |
Yes, the 16kw inverters may not be able to write sensors on the rs485, see this issue I raised: #156 (When trying to write to a 16kw inverter via rs485 the add-on would crash). Adding date_time onto the home assistant interface, and then changing the value there, updated the inverter with the correct time and it resolved an issue for me where the inverter was trying to charge the battery at the wrong time of day (for some reason the inverter had jumped forward 12 hours after being without an internet connection for a few days). |
It is definitely not a failure of the accessory, looking at it closely it is not able to change the time either with deye cloud or with solarman smart. apparently the value changes but when you check it again it still has the previous one |
I have seen that the time change is working again from the Solarman Smart application, in the plugin it still does not write the change to the inverter. |
hello, good morning, I have another new proposal. I don't know if the same would happen in South Africa, but in Spain, I think that due to the frequency of the network, our inverters have the ugly habit of being delayed by a few minutes every 30 or 40 days. I have tried to put the hours and minutes as the new sensor but it seems that there are 2 options for the same record and I have no idea how to put it. The idea would be once set to make an automation with home assistant to synchronize the time of the inverter. Thanks and regards.
The text was updated successfully, but these errors were encountered: