core icon indicating copy to clipboard operation
core copied to clipboard

Lights not turning on off

Open dcmeglio opened this issue 2 years ago • 12 comments

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

  1. 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

dcmeglio avatar Jun 03 '22 02:06 dcmeglio

There's no additional logs after that?

alexyao2015 avatar Jun 30 '22 00:06 alexyao2015

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.

dcmeglio avatar Jul 06 '22 00:07 dcmeglio

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,.

dcmeglio avatar Jul 24 '22 21:07 dcmeglio

That would only happen if your config was erased somehow

alexyao2015 avatar Jul 24 '22 22:07 alexyao2015

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.

dcmeglio avatar Jul 24 '22 22:07 dcmeglio

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

alexyao2015 avatar Jul 24 '22 22:07 alexyao2015

Alright, I'll monitor if that file gets deleted and see if I can figure out what's going on

dcmeglio avatar Jul 24 '22 23:07 dcmeglio

@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?

dcmeglio avatar Aug 09 '22 00:08 dcmeglio

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.

dcmeglio avatar Aug 13 '22 14:08 dcmeglio

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.

alexyao2015 avatar Aug 13 '22 15:08 alexyao2015

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?

dcmeglio avatar Aug 13 '22 15:08 dcmeglio

This issue has been marked as stale due to no activity and will be closed in 7 days.

github-actions[bot] avatar Oct 13 '22 04:10 github-actions[bot]