ZMC v3. Whole house audio step by step Part 3

Show or discuss your existing Home automation project here, so a detailed explanation!.....

ZMC v3. Whole house audio step by step Part 3

Postby AshaiRey » Sat Feb 08, 2014 2:10 pm

Buttons, events en script

The XAP800 is a device that can be controlled via the serial port. To do this you just have to send a text string with the command to execute and that's it. However many commands also give a result back so you need a callback script too. The homeseer example for serial communication tells you to use a separate callback script. Although this is a clean way to do it you will run into problems because the communication is a-synchronic. For example when you ask the device which gate is active and you need to act on the result then the following happens. The gate request is send in and for the script things are finished and it will continue processing then next command. But it hasn't had the correct state yet so processing will fail. You can work around this behavior in various ways by using delays, virtual devices and much more but a more elegant method is used here. I have everything in one script, including the callback functionality. This way I can monitoring constantly the value of variables, also those coming from the callback functions and let the script wait no longer then necessary before continuing processing. To do this the script is loaded when you connect to the device. After that you can call the various methods in the script and the script takes care of the timing, switching en reporting back.

To make the script work you a few things
- A few HomeSeer devices for control and to display state.
- A HomeSeer group called Audio System.
- An INI file (grab it here => http://www.zoelen.net/site/Uploads/AZ_ZMC3.zip )
- Optional images for the buttons

The whole system is controlled by just one script and an ini file. I've include the ini file that I have in use. It's well commented so it would be simple for you to make the changes to reflect your situation. Parts that are marked as dynamic can be left alone since they are filled in by the system. The ini file must be placed in the HomeSeer config folder.
Have a special look at the section [SPEAKTOME] since this contains also a few setting that are used overall

; --==[ START ZMC VR SYSTEM ]==--
[SPEAKTOME]
MIGRAINE_STATE_DEVICE
Remark:
If this device is ON then none of the rooms will have any announcement nor music to prevent extra burden to the migraine patient.

STATIONNAME_DEVICE
Remark:
This device holds the name of the selected radio station. Nice to have for HSTouch

; The following devices must ALL have the same device letter
FIRST_VOLUME_DEVICE="Z71"
FIRST_RADIO_SPEECH_DEVICE="Z81"
FIRST_MUTE_DEVICE="Z91"

These three settings define the button range you used. For each setting it counts at the first device so volume button 1 is here device code Z71 and the first mute button have a device code of Z91.
Make sure that all three ranges have the same house letter, in this case it is the Z.

reset.png
reset.png (16.91 KiB) Viewed 2927 times

The ZMC RESET section contains the default setting for the system how I prefer it. You should use Gware and tune the various levels to your own liking and fill in the values in this section. Just in case you have to reset your system back to a state where you know that all sound levels are correct. A reset can be done with the command AZ_ZMC3.vb("Main", "RESET")

buttons.png
buttons.png (30.51 KiB) Viewed 2927 times

Make for each room or controlled speaker a device of the type 'status only' and call it volume, another device of type 'status only' called 'speech or radio' and a third device called 'Mute'. This last device is a virtual device. The first two devices will give you state information about the system and can be used for example on a HSTouch screen. The mute button actually will mute the output on the XAP800.

turnoff.png
turnoff.png (12.42 KiB) Viewed 2927 times

For the events you need two events for each room. One to turn the sound off and another two to do the mute and unmute command. Also there must be 2 events to connect and disconnect the XAP800 and two events to start and stop the media player.
Each event calls the ZMC script with a command and provides parameters for the command to execute.
Remark:
At places where you can se the room name you can also use the word ALLES (Dutch for ALL) to control all rooms at once.

About the script, you can find it here => http://www.zoelen.net/site/Uploads/AZ_ZMC3.zip
The script is setup in a modular way where you call each method. I've include the whole script here so you will probably have functionality that you don't use (yet). Don't be put off by the complexity of it at first glance. It's just doing the same trick over and over again.

What to do first.
You have to fill in the section called GLOBALY USED VARIABLES at the start of the script to match your situation. If you used the suggested naming of events and buttons this far than you only have to check

CONNECTIONSTRING
SERIALPORTNUMBER

Have also a look at
WavPath (I use HSPRO. Your setup may vary)

DEVICESTRING_ON
DEVICESTRING_OFF
Remark :
These two variables assume that you use images for the speaker on and off state. If you can't find those images on your system then get these.
Muziek-uit.png
Muziek-uit.png (1.6 KiB) Viewed 2927 times
and
Muziek-aan.png
Muziek-aan.png (1.28 KiB) Viewed 2927 times


With everything in place connect to the XAp800 by starting the connect event (AZ_ZMC3.vb("Connect") )
This will open up the serial connection and enable the callback function. Your system is ready to take commands. At the start of the script you can find all implemented commands. For the daily use of audio system the following commands are used
AAN (English: ON)
UIT (English: OFF)
OMROEP (English: ANNOUNCEMENT)
RESET

Remark:
Using the words AAN and UIT has preference over the English versions because they do not interfere with reserved scripting words in vbscript.

kitchenon.png
kitchenon.png (12.74 KiB) Viewed 2927 times

To turn on make an event that will trigger for example due to a motion sensor in the kitchen. Let the event fire the script with AZ_ZMC3.vb("Main","KITCHEN;AAN;1080"). This will turn on the music in the kitchen for 1080 seconds (18 minutes). After this period of time the music will turn automatically off by calling the event '<roomname> music uit' event. If the triggers fire again in this period then the timer will be reset.

The mute event that should trigger an event that mute the system with AZ_ZMC3.vb("SetMute","0|8|O|1")
(note: can't upload image for this because 6 is the max. on this forum)
In this example the 8 stands for the room. If you look in the ini file you can see that room8 is the bathroom (badkamer). I didn't substitute the room number by their names to keep the serial XAP800 command as similar as possible to what you can find in the XAP800 manual. This will simplify looking up parameters if you need them. The same will happen for the unmute command AZ_ZMC3.vb("SetMute","0|8|O|0")

This is the basic version of the ZMC audio system. But it can do much more with it such as announcements.

However that is something for the next part
See all parts together at http://www.zoelen.net/ZMC.htm
Bram
AshaiRey
Senior Member
Senior Member
 
Posts: 1297
Joined: February 2009
Location: Netherlands

Re: ZMC v3. Whole house audio step by step Part 3

Postby Esteban » Sat Feb 08, 2014 10:12 pm

Well, you couldn't have timed this post any better. :)
Thanks for sharing the script, I'll be sure to check it out this weekend!
Esteban
Forum Moderator
Forum Moderator
 
Posts: 677
Joined: January 2008
Location: Netherlands


Return to Home Automation Projects

Who is online

Users browsing this forum: No registered users and 1 guest