Page 1 of 1

Change virtual switch depending on state of JSON

Posted: Wednesday 20 October 2021 21:06
by LordMax
Hi!

I have made a simple python script that will return "LOCKED" or "UNLOCKED" on my door using Verisure's API (a swedish security company). How do I implement it in domoticz so that the virtual switch changes state depending on the JSON value? My script looks like this:

Get status:

Code: Select all

import verisure

session = verisure.Session('xxxx', 'xxxx')
session.login()
overview = session.get_overview()
session.logout()

for i in overview['doorLockStatusList']:
    print(i['lockedState'])
Change lock status:

Code: Select all

import verisure

session = verisure.Session('xxxx', 'xxxx')
session.login()
overview = session.get_overview()

for i in overview['doorLockStatusList']:
    lockState = i['lockedState']
    
    if lockState == "LOCKED":
        session.set_lock_state("xxxxxx", "xxxx xxxx", "unlock")
        print(i['lockedState'])
        
    if lockState == "UNLOCKED":
        session.set_lock_state("xxxxxx", "xxxx xxxx", "lock") 
        print(i['lockedState'])        
        
session.logout()
Thanks beforehand!
Best regards Max

Re: Change virtual switch depending on state of JSON

Posted: Wednesday 20 October 2021 23:36
by waltervl
Here someone made some python scripts to do so.
https://github.com/jdeluyck/verisure-domoticz

Would be better if someone would made a python plugin out of it.

Re: Change virtual switch depending on state of JSON

Posted: Thursday 21 October 2021 0:28
by LordMax
There isnt that good of a tutorial on how to implement it. How do I link my Virtual Dummy to the plugin?

Re: Change virtual switch depending on state of JSON

Posted: Thursday 21 October 2021 0:35
by waltervl
The github example is pretty good documented.
You can learn from it too. That is always a nice feature, that you learn something by doing it :-)

I personally cannot give you more hints. Perhaps someone else.

Re: Change virtual switch depending on state of JSON

Posted: Thursday 21 October 2021 10:58
by LordMax
Is it possible to use the script I have in my main post for Domoticz? If so, how and where do I implement it? The plugin you shared has a lot more in it than I will probably ever use, I only have a doorlock, the first scirpt I posted returns "LOCKED" or "UNLOCKED" and the second script just needs to be ran to toggle the lock state of the door.

Thanks beforehand!
Best regards Max

Re: Change virtual switch depending on state of JSON

Posted: Thursday 21 October 2021 15:29
by LordMax
Hi again,

I have solved it in a different way, I made my python script post the on/off json to the virtual switch depending on the state, and putting the python script inside Windows Task Scheduler so that it updates every 5 seconds, the only problem now is that I need to add the "on/off action" to my script. How do I trigger a python script on a Windows Machine via the "on action" and "off action"?


Thanks beforehand!
Best regards Max

Re: Change virtual switch depending on state of JSON

Posted: Thursday 21 October 2021 16:11
by waltervl
LordMax wrote: Thursday 21 October 2021 15:29 Hi again,

I have solved it in a different way, I made my python script post the on/off json to the virtual switch depending on the state, and putting the python script inside Windows Task Scheduler so that it updates every 5 seconds, the only problem now is that I need to add the "on/off action" to my script. How do I trigger a python script on a Windows Machine via the "on action" and "off action"?


Thanks beforehand!
Best regards Max
Put it in the scripts folder I suppose. But I guess you tried this and it is not working..... What error do you get in the log file if you switch on/off. Most likely that will give a hint.

Re: Change virtual switch depending on state of JSON

Posted: Thursday 21 October 2021 18:26
by EddyG
Did you try to put in:

Code: Select all

script:///<path to script>/<scriptname.py>
Make sure that in the top of your python script there is a reference to the python executable.