diyhue / diyHue

Main diyHue software repo
https://diyhue.org/
Other
1.56k stars 279 forks source link

Creating routines doesn't work properly. #216

Closed jespertheend closed 2 years ago

jespertheend commented 5 years ago

When I create a new (wake up) routine from the app, the created routine doesn't show up anywhere so I can't modify or delete it. The routine also doesn't trigger. In the Accessory setup screen of the app a Hue tap switch is visible without a name, when I tap it I get to an infinite loading screen.

Here's my config.json, not the entire config.json but only the added entries after I created the routine:

{
    "resourcelinks": {
        "1": {
            "classid": 20101,
            "description": "Wake up 1 behavior",
            "links": [
                "/sensors/1",
                "/schedules/1",
                "/schedules/2",
                "/groups/1",
                "/rules/1",
                "/scenes/12",
                "/scenes/13"
            ],
            "name": "Wake up 1",
            "owner": "ae7b564ee6f511e99cfbb827eb631fbb",
            "recycle": false,
            "type": "Link"
        }
    },
    "rules": {
        "1": {
            "actions": [
                {
                    "address": "/schedules/2",
                    "body": {
                        "status": "enabled"
                    },
                    "method": "PUT"
                },
                {
                    "address": "/sensors/1/state",
                    "body": {
                        "flag": false
                    },
                    "method": "PUT"
                },
                {
                    "address": "/groups/1/action",
                    "body": {
                        "scene": "13"
                    },
                    "method": "PUT"
                }
            ],
            "conditions": [
                {
                    "address": "/sensors/1/state/flag",
                    "operator": "eq",
                    "value": "true"
                }
            ],
            "created": "2019-10-06T14:57:30",
            "lasttriggered": "none",
            "name": "L_04_tTOT9_Start",
            "owner": "ae7b564ee6f511e99cfbb827eb631fbb",
            "recycle": true,
            "status": "enabled",
            "timestriggered": 0
        }
    },
    "schedules": {
        "1": {
            "command": {
                "address": "/api/ae7b564ee6f511e99cfbb827eb631fbb/sensors/1/state",
                "body": {
                    "flag": true
                },
                "method": "PUT"
            },
            "created": "2019-10-06T14:57:30",
            "description": "L_04_tTOT9_start wake up",
            "localtime": "W127/T15:15:00",
            "name": "Wake up 1",
            "recycle": true,
            "status": "enabled",
            "time": "W127/T15:15:00"
        },
        "2": {
            "autodelete": false,
            "command": {
                "address": "/api/ae7b564ee6f511e99cfbb827eb631fbb/groups/0/action",
                "body": {
                    "scene": "12"
                },
                "method": "PUT"
            },
            "created": "2019-10-06T14:57:30",
            "description": "L_04_tTOT9_trigger end scene",
            "localtime": "PT00:01:00",
            "name": "L_04_tTOT9",
            "recycle": true,
            "starttime": "2019-10-06T14:57:30",
            "status": "disabled",
            "time": "PT00:01:00"
        }
    },
    "sensors": {
        "1": {
            "manufacturername": "Philips",
            "modelid": "WAKEUP",
            "name": "Wake up 1",
            "recycle": true,
            "state": {
                "lastupdated": "none"
            },
            "swversion": "1.0",
            "type": "CLIPGenericFlag",
            "uniqueid": "L_04_tTOT9"
        }
    }
}
mariusmotea commented 5 years ago

You forget to provide the details. What instalation os, mobile os , mobile app...

jellewie commented 5 years ago

You forget to provide the details. What instalation os, mobile os , mobile app...

Although I agree that this is useful information, this is not stated in the bug report format? Should I now open a bug report that this info is not in the bug report information...??

jespertheend commented 5 years ago

Oh sorry, I'm running on a raspberry pi zero w (raspbian). And I've also tried it on a raspberry 3 b with similar results. I'm using the official iOS Hue app 3.29.0 (10942) And I'm not sure where I can find the currently running diy hue version but I think it's pretty recent?

mariusmotea commented 5 years ago

Did you had something else paired with current Hue App? i don't understand from where the app see a Hue Tap Switch, as the only sensor in the config is the logical one for daylight. Can you reset the app data to factory defaults (reinstall?) ?

jespertheend commented 5 years ago

I just reinstalled the hue app and I'm still getting the same behaviour. I've attached some screenshots that show the issue. Is there a log I can give you? Or perhaps I can make a bunch of rest calls to figure out what's going on?

image image image

Fisico commented 4 years ago

I have the exact same behavior on my iPhone and iPad when I create a wakeup routine. I can create it, I see it in the config, but not in the app. Also a blank tap switch is added automatically to the bridge.

mariusmotea commented 4 years ago

Fortunately i have an iPhone from my job. I will check if is possible to install the app.

jespertheend commented 4 years ago

Is this not happening on android then? I thought this was a global issue.

mariusmotea commented 4 years ago

The Hue apps have total different behaviour. I think they use different developers.

jespertheend commented 4 years ago

Ah I wasn’t aware of that, if you need anything let me know

mariusmotea commented 4 years ago

I can see on my Iphone Hue app the Hue Tap sensor. I will look forward to see what is happening...

Fisico commented 4 years ago

I can see on my Iphone Hue app the Hue Tap sensor. I will look forward to see what is happening...

do you see the routine you created before? In my case it is not showing up. But it gets added to the config.

alexyao2015 commented 4 years ago

I only use android and my routines show up fine. There is no hue tap sensor listed. I just have a problem where routines don't trigger at all.

Once the routine actually starts, I predict that the lights will turn on but won't fade in properly due to #169.

alexyao2015 commented 4 years ago

@jespertheend Can you provide a debug log?

jespertheend commented 4 years ago

Sure can do. Is there a specific path where I can find the log or should I do journalctl -fu hue-emulator?

alexyao2015 commented 4 years ago

I believe this? https://askubuntu.com/questions/864722/where-is-journalctl-data-stored Make sure to enable debug mode: https://diyhue.readthedocs.io/en/latest/AddFuncts/debug.html And capture logs when you add a routine.

Ask Ubuntu
Where is "journalctl" data stored?
When I issue journalctl I get a massive log of all system services, but where is all this information stored?
Enable debug mode — diyHue 1.0 documentation
jespertheend commented 4 years ago

Alright here's the log from the moment I tap 'save' in the create routine screen on the app: creating wakeup routine.log

I also tried restarting the app to see if it would log anything on startup, but it doesn't log anything at all.

Here's the log before creating the routine: config1.json.txt

And this is after creating the routine: config2.json.txt

alexyao2015 commented 4 years ago

I can only assume that this is highly related #233 and that issue has been pretty tough for me to find at least.

jespertheend commented 4 years ago

Hmm alright, that seems tough. Are you able to reproduce the issue at all? I can have a look at it if you want. I’m able to reproduce the issue consistently. Do you think the error thrown in the log file is related?

alexyao2015 commented 4 years ago

I am able to reproduce it. It's a combination of the rules processor not being called and the rules not being evaluated correctly.

jespertheend commented 4 years ago

I just tried to create a wake up routine with an android phone and this is working fine, I can also see this routine show up on my iPhone. There seems to be a difference in the sensors config between wake up routines created by iOS and Android:

//created with iOS
        "3": {
            "manufacturername": "Philips",
            "modelid": "WAKEUP",
            "name": "Wake up 2",
            "recycle": true,
            "state": {
                "flag": false,
                "lastupdated": "none"
            },
            "swversion": "1.0",
            "type": "CLIPGenericFlag",
            "uniqueid": "L_04_n8Bsg"
        },

//created with android
        "4": {
            "config": {
                "on": true
            },
            "manufacturername": "Philips",
            "modelid": "WAKEUP",
            "name": "Sensor for wakeup",
            "recycle": true,
            "state": {
                "flag": false,
                "lastupdated": "none"
            },
            "swversion": "A_1934129020",
            "type": "CLIPGenericFlag",
            "uniqueid": "L_04_4MjVd"
        }

There also seems to be a difference in schedules but I'm not sure which one was created by which OS

// created by iOS I think
        "4": {
            "autodelete": false,
            "command": {
                "address": "/api/9b193796e9cb11e98c07b827eb631fbb/sensors/3/state",
                "body": {
                    "flag": true
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:41:48",
            "description": "L_04_n8Bsg_start wake up",
            "localtime": "2019-11-14T21:43:00",
            "name": "Wake up 2",
            "recycle": true,
            "status": "enabled",
            "time": "2019-11-14T21:43:00"
        },
        "5": {
            "autodelete": false,
            "command": {
                "address": "/api/9b193796e9cb11e98c07b827eb631fbb/groups/0/action",
                "body": {
                    "scene": "4"
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:41:48",
            "description": "L_04_n8Bsg_trigger end scene",
            "localtime": "PT00:01:00",
            "name": "L_04_n8Bsg",
            "recycle": true,
            "starttime": "2019-11-14T20:43:00",
            "status": "disabled",
            "time": "PT00:01:00"
        },

//created by android I think
        "6": {
            "autodelete": false,
            "command": {
                "address": "/api/5aec0aaa072011eaab11b827eb631fbb/sensors/4/state",
                "body": {
                    "flag": true
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:51:02",
            "description": "L_04_4MjVd_start wake up",
            "localtime": "2019-11-15T06:30:00",
            "name": "Wake up 3",
            "recycle": true,
            "status": "enabled",
            "time": "2019-11-15T06:30:00"
        },
        "7": {
            "autodelete": false,
            "command": {
                "address": "/api/5aec0aaa072011eaab11b827eb631fbb/groups/0/action",
                "body": {
                    "scene": "6"
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:51:02",
            "description": "L_04_4MjVd_trigger end scene",
            "localtime": "PT00:01:00",
            "name": "L_04_4MjVd",
            "recycle": true,
            "starttime": "2019-11-14T20:51:02",
            "status": "disabled",
            "time": "PT00:01:00"
        }

Either way, it seems to be working somewhat properly. The transition is a bit messed up but I haven't updated diyhue with fix #237 yet. The reason why it wasn't working at all at first was because the time zone on my raspberry pi was not set correctly.

jellewie commented 4 years ago

(Talked with @jespertheend) I still have some problems with routines,

But I found out that the time was wrong, asked jesper and that's now fixed. some problems have ben fixed.

Like a wake-up routine at 20:00 with -10 transition, results in a 20:20 routine who starts at 20:10. No clue why. trying to figure it out, will post here If I have more details.

If I connect a dummy ESP and record all data, I only get this back at 20:10 type = POST_ url = <ip>/gateways/0xF400/rgb/1 arg 'plain' = '{"status": true, "brightness": 254, "color_temp": 248}' no commands are send after this. Although we checked, I do have the #237 fix, the transition does not seem to work.

mariusmotea commented 4 years ago

I think you are using milight bulbs witch don't support transitiontime, so routines such as wake-up willlnot work properly as they apply the state in ~0.5 seconds instead of x minutes.

jellewie commented 4 years ago

@mariusmotea I'm using https://github.com/sidoh/esp8266_milight_hub And when I send a transaction command to this controller, the transaction does work.

Also it does not explain why my ESP isn't able to receive the transition time command. This is just connected to the wifi itself and returns (verified!) every command given to it. (replies with success command)

The example that worked (tested with Talend)

    type = POST
    ip = 192.168.x.xx/transitions
        json =
    {
      "field": "brightness",
      "start_value": 0,
      "end_value": 255,
      "duration": 100,
      "period": 1000,
      "id": 0,
      "last_sent": 0,
      "device_id": <Device ID as int>,
      "group_id": 1,
      "remote_type": "rgb_cct",
      "current_value": 0
    }

So either there is still something wrong with my tests, which I'm starting to doubt. Or the DIYHUE doesn't send it somehow. So for now I'm just trying to figure out what is going wrong, and I will report back if I found a/the problem. Suggestions are still much appreciated.

GitHub
sidoh/esp8266_milight_hub
Replacement for a Milight/LimitlessLED hub hosted on an ESP8266 - sidoh/esp8266_milight_hub
mariusmotea commented 4 years ago

This portion of code handle the request for milight:

        elif addresses[light]["protocol"] == "milight": #MiLight bulb
            url = "http://" + addresses[light]["ip"] + "/gateways/" + addresses[light]["device_id"] + "/" + addresses[light]["mode"] + "/" + str(addresses[light]["group"])
            method = 'PUT'
            for key, value in data.items():
                if key == "on":
                    payload["status"] = value
                elif key == "bri":
                    payload["brightness"] = value
                elif key == "ct":
                    payload["color_temp"] = int(value / 1.6 + 153)
                elif key == "hue":
                    payload["hue"] = value / 180
                elif key == "sat":
                    payload["saturation"] = value * 100 / 255
                elif key == "xy":
                    payload["color"] = {}
                    (payload["color"]["r"], payload["color"]["g"], payload["color"]["b"]) = convert_xy(value[0], value[1], lights[light]["state"]["bri"])
            logging.info(json.dumps(payload))

try to append following condition:

elif key == "transitiontime":
    payload["duration"] = value * 10 # i think milight use 10x lower values for transitiontime
Fisico commented 4 years ago

I just tried to create a wake up routine with an android phone and this is working fine, I can also see this routine show up on my iPhone. There seems to be a difference in the sensors config between wake up routines created by iOS and Android:

//created with iOS
        "3": {
            "manufacturername": "Philips",
            "modelid": "WAKEUP",
            "name": "Wake up 2",
            "recycle": true,
            "state": {
                "flag": false,
                "lastupdated": "none"
            },
            "swversion": "1.0",
            "type": "CLIPGenericFlag",
            "uniqueid": "L_04_n8Bsg"
        },

//created with android
        "4": {
            "config": {
                "on": true
            },
            "manufacturername": "Philips",
            "modelid": "WAKEUP",
            "name": "Sensor for wakeup",
            "recycle": true,
            "state": {
                "flag": false,
                "lastupdated": "none"
            },
            "swversion": "A_1934129020",
            "type": "CLIPGenericFlag",
            "uniqueid": "L_04_4MjVd"
        }

There also seems to be a difference in schedules but I'm not sure which one was created by which OS

// created by iOS I think
        "4": {
            "autodelete": false,
            "command": {
                "address": "/api/9b193796e9cb11e98c07b827eb631fbb/sensors/3/state",
                "body": {
                    "flag": true
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:41:48",
            "description": "L_04_n8Bsg_start wake up",
            "localtime": "2019-11-14T21:43:00",
            "name": "Wake up 2",
            "recycle": true,
            "status": "enabled",
            "time": "2019-11-14T21:43:00"
        },
        "5": {
            "autodelete": false,
            "command": {
                "address": "/api/9b193796e9cb11e98c07b827eb631fbb/groups/0/action",
                "body": {
                    "scene": "4"
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:41:48",
            "description": "L_04_n8Bsg_trigger end scene",
            "localtime": "PT00:01:00",
            "name": "L_04_n8Bsg",
            "recycle": true,
            "starttime": "2019-11-14T20:43:00",
            "status": "disabled",
            "time": "PT00:01:00"
        },

//created by android I think
        "6": {
            "autodelete": false,
            "command": {
                "address": "/api/5aec0aaa072011eaab11b827eb631fbb/sensors/4/state",
                "body": {
                    "flag": true
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:51:02",
            "description": "L_04_4MjVd_start wake up",
            "localtime": "2019-11-15T06:30:00",
            "name": "Wake up 3",
            "recycle": true,
            "status": "enabled",
            "time": "2019-11-15T06:30:00"
        },
        "7": {
            "autodelete": false,
            "command": {
                "address": "/api/5aec0aaa072011eaab11b827eb631fbb/groups/0/action",
                "body": {
                    "scene": "6"
                },
                "method": "PUT"
            },
            "created": "2019-11-14T20:51:02",
            "description": "L_04_4MjVd_trigger end scene",
            "localtime": "PT00:01:00",
            "name": "L_04_4MjVd",
            "recycle": true,
            "starttime": "2019-11-14T20:51:02",
            "status": "disabled",
            "time": "PT00:01:00"
        }

Either way, it seems to be working somewhat properly. The transition is a bit messed up but I haven't updated diyhue with fix #237 yet. The reason why it wasn't working at all at first was because the time zone on my raspberry pi was not set correctly.

it just worked because you created the routine with the andorid app right?

my raspy timezone is set correctly and the routines are not working if i add them via the iphone app.

alexyao2015 commented 4 years ago

I'm seeing this error in my logs

Exception in thread Thread-9:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/hue-emulator/HueEmulator3.py", line 1165, in daylightSensor
    loc = Location(('Current', bridge_config["config"]["timezone"].split("/")[1], float(bridge_config["sensors"]["1"]["config"]["lat"][:-1]), float(bridge_config["sensors"]["1"]["config"]["long"][:-1]), bridge_config["config"]["timezone"], 0))
IndexError: list index out of range
alexyao2015 commented 4 years ago

Turns out that error was due to a timezone without a /. @mariusmotea Where did you get timezone values from originally? It seems that values such as CET, CST6CDT (all without a /) are invalid.

Fisico commented 4 years ago

@alexyao2015 so how do i fix this now? as it seems resolved for @jespertheend ?

my config: https://pastebin.com/0BYr0LDf

Pastebin
[JSON] { "alarm_config": { "mail_from": "your_email@gmail.com", - Pastebin.com
erice1031 commented 4 years ago

Hi, DIYHUE user for a few months and am having same issue with routine not working. Looks like this issue has been open for a while, why no response to the comment above with potential resolution? (Quoted below)

Is DIYHUE development dead or alive? For some context, I know people have lives to live. No disrespect meant btw. I really appreciate the work you guys have done here, amazing and so useful. Thank you x💯

Turns out that error was due to a timezone without a /. @mariusmotea Where did you get timezone values from originally? It seems that values such as CET, CST6CDT (all without a /) are invalid.

alexyao2015 commented 4 years ago

Planning on a refactor and yes time has been limited.