Change virtual switch depending on state of JSON Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
LordMax
Posts: 35
Joined: Saturday 10 April 2021 21:24
Target OS: Windows
Domoticz version: 2021.1
Contact:

Change virtual switch depending on state of JSON

Post 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
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Change virtual switch depending on state of JSON

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
LordMax
Posts: 35
Joined: Saturday 10 April 2021 21:24
Target OS: Windows
Domoticz version: 2021.1
Contact:

Re: Change virtual switch depending on state of JSON

Post by LordMax »

There isnt that good of a tutorial on how to implement it. How do I link my Virtual Dummy to the plugin?
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Change virtual switch depending on state of JSON

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
LordMax
Posts: 35
Joined: Saturday 10 April 2021 21:24
Target OS: Windows
Domoticz version: 2021.1
Contact:

Re: Change virtual switch depending on state of JSON

Post 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
LordMax
Posts: 35
Joined: Saturday 10 April 2021 21:24
Target OS: Windows
Domoticz version: 2021.1
Contact:

Re: Change virtual switch depending on state of JSON

Post 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
User avatar
waltervl
Posts: 5851
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Change virtual switch depending on state of JSON

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Change virtual switch depending on state of JSON

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest