MiCasaVerde Vera UI5, UI6, UI7 Plugin

Questions and comments specific to a particular plugin should go here.
User avatar
kgschlosser
Site Admin
Posts: 4309
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by kgschlosser » Fri Dec 08, 2017 5:29 am

I also made some cool additions.

you can now access devices, rooms, installed_plugins by directly keying in the name. The name has to be all lowercase and any spaces have to be replaced with an underscore. if the name on the vera has any special characters you cannot use this method.

vera.devices.some_device_name
vera.rooms.some_room_name


I also added a direct grab of a device from the room and this one can be done directly from the vera instance.
vera.media_room.overhead_lights

I also change the grabbing of devices. there is no longer get_device or get_room.. all of the gets are now gone. save for 2. and those 2 are get_variables and get_functions.

to grab an item by it's id or it's name use.

vera.devices['some device name']
vera.devices[10]
If you like the work I have been doing then feel free to Image

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by holdestmade » Fri Dec 08, 2017 4:40 pm

Hey,

Sorry been busy of late so not been able to test this as much as I'd like.

Anyway, tried the latest version and build went fine using:

Code: Select all

from micasaverde_vera import vera_build
vera_build.build_files('192.168.1.205', log=True)
It took about 30 seconds.

When I put this in a script:

Code: Select all

import micasaverde_vera
vera = micasaverde_vera.connect('192.168.1.205')
I got the errors below, think they are the same errors as before (Fri Dec 01, 2017 9:11 am)

Cheers



16:35:54 Traceback (most recent call last):
16:35:54 Python script "4", line 7, in <module>
16:35:54 vera = micasaverde_vera.connect('192.168.1.205')
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\__init__.py", line 342, in connect
16:35:54 return __Vera(ip_address)
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\__init__.py", line 303, in __init__
16:35:54 _VeraBase.__init__(self, ip_address)
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\__init__.py", line 411, in __init__
16:35:54 self.devices = self.__build(Devices, 'devices', data)
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\__init__.py", line 457, in __build
16:35:54 data.pop(key, None)
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\devices.py", line 34, in __init__
16:35:54 self._devices += [self.__build(device)]
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\devices.py", line 47, in __build
16:35:54 self.ha_gateway.scenes = Scenes(self.ha_gateway, device)
16:35:54 File "C:\Program Files (x86)\EventGhost\lib27\site-packages\micasaverde_vera\scenes.py", line 43, in __init__
16:35:54 for keys in self._variables[state['service']].keys():
16:35:54 KeyError: u'urn:micasaverde-com:serviceId:ZWaveDevice1'

User avatar
kgschlosser
Site Admin
Posts: 4309
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by kgschlosser » Fri Dec 08, 2017 6:35 pm

well i'll be damned. you found a bug in the Vera. this is a largish coding flaw on their part. I can code around it but I do not know how the vera will react if any variables associated with that service get changed.
If you like the work I have been doing then feel free to Image

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by holdestmade » Fri Dec 08, 2017 7:07 pm

If it is scenes, I don't use them anyway and I guess same can be achieved with eg anyway ?

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by holdestmade » Fri Dec 08, 2017 7:07 pm

Might not be good for others who do use them though I guess!

holdestmade
Experienced User
Posts: 174
Joined: Thu Dec 04, 2014 2:44 pm

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by holdestmade » Fri Dec 08, 2017 7:10 pm

Something else that's weird. When I try and run the module as above it halts the Vera and the rfxtrx loses its com port. It's OK once I restart Vera. At same time it stops Vera talking to my rti remote processor and that needs a reboot too.

User avatar
kgschlosser
Site Admin
Posts: 4309
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by kgschlosser » Fri Dec 08, 2017 8:03 pm

it is with the scenes. But the SceneController1 class has to get constructed..


The problem is in the device file for SceneController1 this is where all of the services that are associated with that device are listed.

and what is listed in there is service SceneController1 and service HADevice1

but when grabbing the actual live data from your Vera you can look at the xml yourself. find device #2 this should be the scene controller device. But in there it lists off all of the variables and their current values along with the service they are attached to. and in your data there are variables that are associated with ZWaveDevice1 which i did not build into the class because the device file does not have it listed. So this is a rather large bug. because how if the Vera supposed to know how to handle any changes to those variables if the service file for those variables has not loaded... It can't. there has got to be some side affects on the Vera from that not being listed. I can send you a modified copy of your D_SceneController1.xml.lzo file that will include the missing bits. Or i can code around it. I am thinking i am going to code around it for the time being. I have an inside man at MIOS I have already sent him a message asking about it.

But i did patch the repo so you should be good to go with this one. it will get past that error.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4309
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by kgschlosser » Sun Dec 10, 2017 7:52 am

OK so this is what I have discovered. there is a service called ZWaveDevice1 that does not have a service file. nor is the service listed in any of the classes. so what I did was I manually created the needed file and it will dynamically add the service to a device if it is needed. At the same time I have added dynamic addition of any service. in the event that there is a service that happens about that was not put into a device file. I also changed up the import system to try rebuilding the files one time if there is an import error for a specific service/device. There will also be one printed error if this happens. If I didn't do this the program would get stuck in a rebuilding loop which is not a good thing. So this will allow the program to continue along it's merry way simply not allowing that device to be added or if it is a service the device will not have access to any functions or variables that service gives access to.

The most recent update is on GitHub. let me know if there are any other errors.
If you like the work I have been doing then feel free to Image

PBCVera
Posts: 2
Joined: Wed Dec 20, 2017 2:51 pm

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by PBCVera » Wed Dec 20, 2017 3:01 pm

Ok so dumb question, wonder if anyone can help. I want to use the Micasa plugin to set the volume on my pc based on the value from a virtual dimmer on my Vera unit. The reason I want to do this is my home theater pc is wired to my upstairs and downstairs stereo. I want to control the dimmer with my Alexa (easy). I could set up a scene and send a volume down or up command through http command in Luup to EG easy enough. What I dont like is the Alexa syntax. For example, to control a scene called volume down you would say "Alexa, turn on volume down" but that sounds sloppy. Going with a dimmer would be nicer. "Alexa, set volume control to 50%" to set a dimmer to 50 and then the value is sent to EG via Micasa plugin and that level is plugged into set volume command.

Im not a Python programmer at all, but I can set up Macros. The pieces are all here, but I can't make it work. I don't think this can be done from setting up a basic macro in the Config Tree anyways. I think this needs a piece of script to run after the Trigger event (dimmer switch level changed) to pull the variable and insert into set volume command. Is this possible? Any help would put you on the top of Santa's nice list.

User avatar
kgschlosser
Site Admin
Posts: 4309
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by kgschlosser » Wed Dec 20, 2017 4:12 pm

You should be able to do this with very minimal amount of scripting if any at all.


if you change the virtual dimmer you should see an event for that change in EG. It has been a very very very long time since I have actually used this plugin at all. I do not remember how i set up the payload data. But I am pretty sure I would have used a dictionary to contain the data. If memory serves I included both the old data set and the new data set in the payload. let me go and check. Another option is to use the event string it's self to grab the new value.
If you like the work I have been doing then feel free to Image

User avatar
kgschlosser
Site Admin
Posts: 4309
Joined: Fri Jun 05, 2015 5:43 am
Location: Rocky Mountains, Colorado USA

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by kgschlosser » Wed Dec 20, 2017 5:21 pm

ok so this is what I have done for ya. i created several macros. I went outside the box a little. What this is going to do is it is going to change the volume on the PC to whatever you set that virtual dimmer value to. And it is also going to change the dimmer value to whatever you set the volume to on the PC. I did the latter half so if you want to use Alexa to ask what the sound level is on the PC you are able to. Cool beans eh?


Use:
Copy the code below in it's entirety. open EventGhost. Right click on your computer name at the top of the "Configuration Tree" (usually on the right unless you have moved it) then click on paste. This will make a new folder with the macros in it.

There are going to be 4 things you will have to change. I have indicated those things as Change 1, Change 2 and so on and so forth.

CHANGE 1 and CHANGE 2 - you are going to need to set the virtual dimmer using the Vera UI so we can get an Event in EG for the device. drag and drop this event into each of the macros that contain CHANGE 1 and CHANGE 2. You will then edit those new events and delete everything at the end up to the last "." (it should be all numbers the percentage the dimmer is set to) then add a "*" (no quotes) to the end after the ".". Do this for both of the events. then delete the old events that have CHANGE in them.

the next 2 are a wee bit more complex. put are still pretty easy.

CHANGE 3 - You will want to create a new macro with the action System-->Audio-->Set Master Volume. The only thing we are concerned with here is the Device. so just set the Device in it click on apply and then close.
Right click on that newly created action and click on copy as python.
Double click on the CHANGE 3 item and it will open the python script editor. At the very bottom of the script paste in that python code you copied from the last step. You are going to need to copy the device from that new line to the line that is right above it.. you want everything between the single quotes ' ' at the end. replace the PASTE YOUR DEVICE HERE then delete the line you pasted into the script at the end and save it. You can remove the CHANGE 3 by renaming the item by right clicking on it.

CHANGE 4 - Same deal as above except we will want to use the action MiCasaVerde Vera UI5 UI6 UI7-->Set Light Level to get the device from
make sure you set the device to the same virtual switch that Alexa is changing.

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<EventGhost Version="WIP-2017.10.31-06.09.51">
    <Folder Name="Vera Set PC Volume">
        <Macro Name="Set Volume (active)" id="500">
            <Event Name="CHANGE 1    MiCasaVerdeVera.My Home.Office.Main Recessed.Dimmable-Switch.Level.*"/>
            <Action>
                EventGhost.EnableItem(XmlIdLink(501))
            </Action>
            <Action>
                EventGhost.DisableItem(XmlIdLink(503))
            </Action>
            <Action Name="CHANGE 3     Setting Volume Level">
                EventGhost.PythonScript(u"if 'level' in eg.event.payload:\n    eg.plugins.System.SetMasterVolume(eg.event.payload['level'], u'PASTE YOUR DEVICE HERE')\n    ")
            </Action>
        </Macro>
        <Macro Name="Set Volume (not active)" id="502" Enabled="False">
            <Event Name="CHANGE 2    MiCasaVerdeVera.My Home.Office.Main Recessed.Dimmable-Switch.Level.*"/>
            <Action>
                EventGhost.EnableItem(XmlIdLink(500))
            </Action>
            <Action>
                EventGhost.DisableItem(XmlIdLink(502))
            </Action>
        </Macro>
        <Macro Name="Set Switch Level (active)" id="503">
            <Event Name="System.Volume"/>
            <Action>
                EventGhost.EnableItem(XmlIdLink(502))
            </Action>
            <Action>
                EventGhost.DisableItem(XmlIdLink(500))
            </Action>
            <Action Name="CHANGE 4    Setting Switch Level">
                EventGhost.PythonScript(u"eg.plugins.Vera.Dimmer('PASTE YOUR DEVICE HERE', eg.event.payload + '%')")
            </Action>
        </Macro>
        <Macro Name="Set Switch Level (not active)" id="501" Enabled="False">
            <Event Name="System.Volume"/>
            <Action>
                EventGhost.EnableItem(XmlIdLink(503))
            </Action>
            <Action>
                EventGhost.DisableItem(XmlIdLink(501))
            </Action>
        </Macro>
    </Folder>
</EventGhost>



The reason for all of the enabling and disabling of the macros is because we do not want to start an infinite loop. The Vera does not care if the value is set to 43 and you set the value to 43 again. it will change it causing an event in EG. and likewise with windows and the Volume. So when the system volume changes we want to disable the macro that receives events from the Vera (because this macro sets the system volume). and enable a dummy macro that when the Vera event comes in it will re enable the Alexa macro and disable the dummy one. This will stop the Alexa one from setting the system volume when it was the system volume that made the change in the first place. I don't know if that makes sense. One of these days I will come up with a way to actually explain it. because it makes no damned sense to me LOL. I have to burn a few brain cells every time i set something like this up.

I have tested this code and it does work properly. Lets make sure this works properly before we address any data syncing issues EG is not running and you change the volume with Alexa. or you change the volume on the PC. The virtual switch will not be the same as what the volume on the PC is. This we will make sure is correct but one step at a time.

Let me know if it works out for ya.

K


****EDIT*****

I forgot to mention. You need to be running EG 0.5 for this to work properly.

Also make sure that you grab the correct event for the Virtual switch. there could be more then one of them. You want the one that is the Level
If you like the work I have been doing then feel free to Image

PBCVera
Posts: 2
Joined: Wed Dec 20, 2017 2:51 pm

Re: MiCasaVerde Vera UI5, UI6, UI7 Plugin

Post by PBCVera » Fri Dec 22, 2017 2:01 am

Thank you for your replies! I will try your code next week after the holidays (pulling a 6 day stretch of 12hr shifts). I will let you know how it works. Happy Holidays!

Post Reply