Edit: I’m going to mess around with this some more and see if I can figure it out. Was just able to put that code directly in my config.yaml file and it said the config was valid.
Edit 2: Okay, got them to show up in entities, so that is progress.
Thanks for putting that together! I’m working through it right now.
I was able to get to “This should create two entities, a basic on/off switch and a sensor that will be able to show what volume source and state.”
No entities show up when I search for HTD in my entities list. Do I have to do something to have HA look at the files I just created? I feel like that step is missing. I trying adding
Ok I have the switch partially working. I can turn on a zone, but can’t turn it off. When I turn it off, the switch reverts to back on after a few seconds. When the zone is off and I use the switch to turn it on, the zone comes on right away! So I did something right.
How does the sensor look in Lovelace for you? Are you using a HACS custom card or something? Here is what my two cards look like:
Also, you included some “State attributes (YAML, optional)”. What is this? I see those are just blank when I made the sensor. Wouldn’t those be variables? That is, power won’t always be true as the power won’t always be on. I guess I don’t get how those state attributes work, could you enlighten me please?
This is awesome that I’ve finally been able to make some progress on this after a year of wanting to get HTD into HA. Thanks again!
Edit: so sometimes just typing this out helps me think through it. I understand now that the State attributes go in the Lovelace card somehow. Can you post the yaml for your Lovelace cards? I think that would be helpful. Still don’t know why my switch will only turn on and not off. The sensor is pulling correct info (power, volume, source, etc) so it’s working in the background.
So I’m not using a custom Card, I basically keep the sensor hidden and will most likely use it as an automation state later when I sit down and tackle some of the other things I want to do with them. (Things like incorporating a volume slider and source selector)
As for the powering on but not off. Do you have a Lync 12 or Lync 6? It’s possible that some of the index items are off in the program (I’d have to get my friend to check if that’s the case). I’ve uploaded my sensors and switch yamls to the git If you want to look, very basic.
To test you can go into the shell of your HA and manually run the script (python3 /config/scripts/htd-lync12.py power 1 off) Additionally if you run the script “as-is” a help text displays showing what the script can do and the syntax as well.
As for my lovelace, it is just like yours (the switch) except I customised the icon to be a speaker instead.
Ah, I see regarding the Lovelace cards. I have a Lync 12, so I think that is all good.
Thanks for uploading those files, it was really helpful for me to find silly mistakes and stuff. I was able to create the separate files for switch and sensor and move the stuff out of my main config file which is good. So satisfying for me to see the green “Configuration valid!” message after messing with this stuff - I have zero programming experience so it’s a steep hill to climb sometimes.
To test you can go into the shell of your HA and manually run the script (python3 /config/scripts/htd-lync12.py power 1 off) Additionally if you run the script “as-is” a help text displays showing what the script can do and the syntax as well.
Ok, I am able to open up the terminal and run that script and it worked! Same thing with power on. So maybe it is something with my switch. FOUND IT! So I didn’t put the python files in a /scripts/ folder, I made one called /HTD instead. So when changed it I wrote Htd with the lowercase d. It works! I guess the old adage “garbage in, garbage out” applies here.
Oh hot damn! When I made the card with multiple zones and put in a title, there is a bit switch at the top that powers everything on and off!
What is the scan interval and why is it not the same for all of the sensors?
Okay so my next project which I’ll have to start on a later date is setting up some sort of automation where if a zone is on for more than N hours or if it’s a certain time turn the zone off. I probably should do something with scenes as well.
This is so cool though. I have a major headache and need to go do something else, but this was very satisfying and I’m so glad I finally made some progress. Thanks so much for the time and support!
So regarding the timer. They’re different because sometimes (and it might just be my instance) the HTD gateway with kind of bork on receiving too many queries simultaneously so I space them out.
Another project I was looking into, the fellow had almost reversed the api but it required setting up a full “stack” as it were to host the application so it was kind of a non starter.
And don’t worry about being a newb. I’m still very much in that bucket and slowly work my way though getting smart logic into my home
Oh one thing that I do is have the “work day” integration setup and have the house automatically turn on my “home office” speaker at the start of the work day and off at the end of it. Helps keep timing to “hey the work day’s done”.
So you need to create some entries in a shell_command.yaml (if you don’t have it create is and don’t forget to add the include line in your configuration (shell_command: !include shell_command.yaml))
alias: HTD_Kitchen_Volume
description: Automation to handle the volume slider for the HTD Zone 1 (kitchen/Livingroom)
trigger:
- platform: state
entity_id: input_number.kitchen_livingroom_volume
condition: []
action:
- service: shell_command.zone1_volume_slider
data_template:
volumevalue: '{{states.input_number.kitchen_livingroom_volume.state | int}}'
mode: single
After adding that so my lovelace card and testing it out by moving it around it successfully changed the volume (up and down).
The HTD only supports a max volume setting of 60 so I made sure my slider was set the same.
Now my speaker card looks like this:
Another side-note, which you’re probably aware of, changing the volume when the speaker is off powers it on, this isn’t the script it’s the way the HTD system works.
I had to basically match out each selection in the list to the appropriate “source” ID in the HTD system. (I basically matched them top down in the HTD app and verified they actually matched).
Now the card looks like this:
And best of all it works.
If anyone wants to comment on the automation and template to help clean it up I’m all ears
Oh wow, that’s a lot of stuff. I currently am just running one source (a Raspberry Pi as an Apple AirPlay device) so I’m just pushing audio (and volume control) out from my phone via AirPlay on the Pi, so just a single source and static volume on HTD.
One thing I’m not getting is reliability in HA. For instance, HA showed all zones were off last night, but this morning one was still on. With that same zone that was on all night and not showing it, when I turn it on in HA, the slider goes back to off in a few seconds, but the zone turns on. Even if I wait for a minute, the sensor still won’t show that the speaker is turned on. But then later on this zone worked fine. The Logbook in HA isn’t super consistent either. Sometimes the switch change shows up, and sometimes the sensor change shows up. And it seems like the sensors are throwing stuff like this up, even though nothing has changed for that zone. Is that the scanning? Looks like this happens regardless of whether I am changing anything or not.
So it has to scan in order to pick up changes made from the HTD app, right? But if you hit the switch right after a scan, then the sensor misses that it changed until the next scan?
So yes, I do encounter that issue occasionally. Although I don’t currently use the sensor portion presently so I can’t say I’ve noticed it much.
You can try modifying the scan_interval: 45
value a bit to smaller values but if you’re running a pi it will probably start taxing the system with the frequent script executions (not taxing THAT much but still additional load on a “minimized” device).
The thing is that the switch itself (the command_line entry) automatically queries the state (I think it’s once a minute, provided you use the state query line like I did) regardless of the sensor so if you want you could potentially just remove the sensor altogether (unless you’re currently using it).
The reason I’m not using it is because I think I’d create an update loop if I query the sensor to populate my volume and source which then triggers the automation to set the volume and source, still got to mull that one over)
I’ve had the odd occasion where the script doesn’t return a value for the json entries but it usually clears up by the next refresh.
For your automation, do you expect a state as a condition? to ensure the system is off I would just set a time is XX then device → switch.htd_zonex → turn off and repeat the action for all the zones. And not worry about a check condition. Then it will force them off regardless.
Oh, I think I don’t understand it it then. I thought that the icon on the switch’s Lovelace card was linked to the sensor. When I commented out the '!includeline in theconfiguration.yaml` file and restarted, I still get the same behavior.
I think I copied everything exactly the way you did, so it should work the same. I wouldn’t know what to change anyway.
Found the issue! I am horrible at looking for things physically, and I guess that transfers over to code as well. Somehow this last line got duplicated in the switch.yaml file and it was for two different zones.
command_state: "python3 /config/HTD/htd-lync12.py query zone 10"
command_state: "python3 /config/HTD/htd-lync12.py query zone 9"
So that was causing the unexpected behavior. My guess is it was “inconsistent” as when zone 9 was on I would get different behavior as to when zone 9 was off.
Ha, I don’t even know what “do you expect a state as a condition” means! I’ll probably do it like i have my locks: at [time] set all locks to closed. Maybe with a scene? That’s what I did before. I do want to investigate node red at some point, perhaps this would be a good chance.
Edit: Also, any idea how to make a group of speakers in HA?
Oookay, I re-read the response and I realise now that you don’t run HA on a pi (that’s for your audio source).
Anyways…
Yeah, “proof-reading” is the bane of most HA issues, especially in the yaml configs (using tabs instead of spaces, not enough spaces, too many spaces etc ) So always double check. As for a group of speakers, I’m not sure, but you can try adding an entry in the groups.yaml file as follows:
Obviously replace the entities with the entity names for your speakers
then reload the groups.yaml in ha and see if you have a new entity called spkr_kitchen.
(Note I haven’t grouped any speakers yet)
Regarding my references to “expecting a state as a condition” I was referring to setting a condition on the automation that it would only fire if the speaker “switch” was on. for example.
I have one Pi that has HASS OS on it and one with Rasbian.
So the group thing worked. I was able to easily add it to my Lovelace card and even changed the icon to show multiple speakers.
I set up a super basic automation so that every night at midnight it’ll “activate” the scene that I saved with all the speakers off. What I need to do is figure out how to give me a notification if the speakers have been one for 3 hours or something. Or, better yet, somehow figure out how to tell HA if anyone is currently connected via AirPlay to Shair-port sync and if not, then ping me and let me know “Your speakers have been on for 10 minutes and aren’t being used.” or something like that. So much easier said than done though - I can’t even figure out how to move my shade groups from configuration.yaml to groups.yaml without it giving me an error.
Okay so probably not to drag this thread out. I would suggest posting that as a new question in the forum as the main integration question has been sorted.
My thoughts would be having a wait action when a speaker turns on with a timeout of 3 hours (and continue on timeout) then when the wait expires send a notification. A choose action would probably work to allow a condition to test if the speaker is still on.
So I just checked my error logs and it’s LOADED with errors from this HTD integration. Haven’t changed anything that I know of, everything is working as expected.
I do have that as well. Personally I ignore it but changing the polling interval (or disabling it and setting a polling interval through an automation) may help minimize it. It could be that the script isn’t getting a timely response from the controller and thus returning empty results.
Not sure why it wouldn’t be doing that. Is it just a specific zone or all of them?
On a side-note I’ve “moved” my system over to using this custom integration Htd gw-sl1 / mc-66 - #104 by UngluedChalice" as it keeps the source and volume identifiers updated at “both” ends per se.
Thank for your help regarding this thread. I’m brand new to hass. I added all files to the custom_components/htd_lync12 folder and inserted the yaml code in the configuration folder via [https://github.com/UngluedChalice/htd-lync12-home-assistant.] When I go to restart HASS I’m getting the following error message.
"Failed to restart Home Assistant
The system cannot restart because the configuration is not valid: Integration error: htd_lync12 - Integration ‘htd_lync12’ not found"
Does anyone know what I’m doing wrong? I’m using the visual studio code server to make changes.
I was successful in integrating the meester files for 6 of my 12 zones. However, when I try to expand the switch and sensors file, I cannot simply continue adding the zones. There appears to be an index of some sort in the py files that I cannot find.
Anyone successful in expanding the meester files into a 12 zone setup?