core
core copied to clipboard
Lights not turning on off
No light turns on or off when I send the command from a harmony remote. I see the log message above in the logs so something is sent but nothing happens.
Steps to Reproduce
- Try to turn on a light from a harmony remote
Expected behavior
Logs
emulated_hue.api -- [192.168.1.34] PUT /api/a103f1fAec6fd654D8dfde5a33da2d46deeCbdF8/lights/48/state
Hardware Info:
- Architecture (Ex: x86, ARM): arm
- Addon version (Ex: stable or dev): dev
- Value of "tag_commit_or_branch" if using dev: master
- OS (Ex: Windows 10, Ubuntu Buster): HAOS
- Hardware (Ex: PC, Raspberry Pi 1/2/3/Zero): pi 3b
Additional context
There's no additional logs after that?
Correct. I switched over to your refactor branch which shows more details that the API key expired. Not sure what causes that to expire? I re-setup the Harmony app and it worked again but I've had this happen a couple times.
I've had this happen again today: 2022-07-24 17:39:57,685 DEBUG emulated_hue.apiv1 -- [192.168.1.34] Invalid username (api key)
And all commands stop working until I re-pair the hub with Harmony,.
That would only happen if your config was erased somehow
Ok, what config are we talking about? What conditions would caused it to be erased? I've had this happen 6 times in 2 months so it seems like something must be up. I'd be happy to help troubleshoot if I know what to look for to confirm your theory.
I'm not sure what could be deleting it, but under normal circumstances it shouldn't have been deleted. I assume you're running it as an addon so the config would be under /config/hass-emulated-hue
Alright, I'll monitor if that file gets deleted and see if I can figure out what's going on
@alexyao2015 a little more info. The emulated_hue.json existed, but the file was empty. I experienced a power outage today. Perhaps that is the situation where the file is not properly being closed?
I can't yet say if it's the cause, but this method could result in what I see https://github.com/hass-emulated-hue/core/blob/61aa3d9e16ba6a6b30cdbc5a09bfd7450222418a/emulated_hue/utils.py#L126
On line 130, you rename emulated_hue.json to emulated_hue.json.backup
You then go into a try/except.
If an exception occurs, all you do is log. So you're left with no config file.
After LOGGER.exception("Failed to serialize to JSON: %s", filename)
You should have os.replace(safe_copy,filename)
to restore the backup.
Of course this doesn't yet tell us the root cause, but it does explain where the file went. If with open(filename, "w") as file_obj:
succeeds but file_obj.write(json_data)
throws an exception for some reason, you'd be left with an empty file since it was opened as writeable (created as zero bytes), but nothing written to it. Additionally logging that shows what exception was thrown and why could help too.
Good point here. That does appear to be an issue. However in your case, you haven't shown any logs resembling that issue. Unless you have logs showing that line, I wouldn't assume that would be the cause of the issue.
That is correct, I have not been able to detect the particular log. How can one access old logs from the addon after the addon restarts?
This issue has been marked as stale due to no activity and will be closed in 7 days.