Skip to content
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

'CheckPresenceOnPing' keeps reenabling security zones when 'no one is at home' #4

Open
user45876 opened this issue Apr 19, 2019 · 1 comment

Comments

@user45876
Copy link

When setting up CheckPresenceOnPing, it keeps reenabling the security zones, when nobody is at home (no device is reachable).
This can be problematic, as this causes a popup on every configured client and also spams the alarm log.

Expected behaviour would be that on 'noone is home' and already activated security zone, nothing is done.

@user45876
Copy link
Author

user45876 commented Apr 19, 2019

Well, without actually knowing what I am doing - this does it for me, AFAICT. Straightened the outputs a little and added a timestamp in front for easier logging.

#!/usr/bin/env python3
import homematicip
from homematicip.home import Home
import ping3
from socket import gaierror
import datetime

config = homematicip.find_and_load_config_file()

SCANABLE_DEVICES = ['192.168.128.101', '192.168.128.108']
ACTIVATE_EXTERNAL_ZONE = True
ACTIVATE_INTERNAL_ZONE = False

DEACTIVATE_ON_PRESENCE = True

def main():
    if config is None:
        print("{} COULD NOT DETECT CONFIG FILE")
        return


    home = Home()
    home.set_auth_token(config.auth_token)
    home.init(config.access_point)

    if not home.get_current_state():
        return
    for ip in SCANABLE_DEVICES:
        try:
            res = ping3.ping(ip)
            if res != None:
                if DEACTIVATE_ON_PRESENCE:
                    for g in home.groups:
                        if isinstance(g, homematicip.group.SecurityZoneGroup) and g.active:
                            print("{} Someone is at home, security zones are active -> deactivating security zones.".format(datetime.datetime.now().strftime("%y%m%d-%H:%M")))
                            home.set_security_zones_activation(False,False)
                            return
                    print("{} Someone is at home, security zones are deavtivated -> do nothing.".format(datetime.datetime.now().strftime("%y%m%d-%H:%M")))
                else:
                    print("{} Someone is at home, security zones are inactive -> do nothing.".format(datetime.datetime.now().strftime("%y%m%d-%H:%M")))
                return
        except gaierror:
            print("Could not resolve {}. Marking it as \"not at home\"".format(ip))


    for g in home.groups:
        if isinstance(g, homematicip.group.SecurityZoneGroup) and g.active:
            print("{} Nobody is at home, security zones are already active -> do nothing.".format(datetime.datetime.now().strftime("%y%m%d-%H:%M")))
            return
    print("{} Nobody is at home, security zones are inactive -> activating security zones.".format(datetime.datetime.now().strftime("%y%m%d-%H:%M")))
    home.set_security_zones_activation(ACTIVATE_INTERNAL_ZONE,ACTIVATE_EXTERNAL_ZONE)

if __name__ == "__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant