Hey- I took a quick look at the actual logic that sends the keypresses to the envisalink. A single command accepts up to 6 characters, according to the DSC spec- so have you tried doing a single service call with 6 chars?
If the DSC only accepts 6 characters that may be the limitation as *71XXXX (XXXX being the code) would be 7 characters. Maybe it’s not possible to send the entire sequence as 1 command? I have found that my script above seems to work fine and as long as I’m not looking at one of the other interfaces when I execute the script I don’t ever see the request for a code. I do still get the error in the HA log file that “we don’t have a code in our cache” every time I use the script but that’s a fairly minor annoyance.
Thanks again for the excellent work on this plugin. It is far easier to interact with than even the Vera DSC plugin.
Ahh okay I see what’s going on.
So the way the DSC works is that it’s entirely asynchronous, even when challenging for code. so if you call something like “disarm” from HASS, we know that we’re going to be challenged for the code, so HASS sends along the code to the pyenvisalink library, and that library will temporarily cache that code until the DSC challenges us for it as we expect it to.
Unfortunately with the keypress service being arbitrary, HASS understandably doesn’t send that code along to the pyenvisalink library since it doesn’t really know what to expect, and thus when the DSC challenges us, we’re not ready for it.
I’m not sure of a great way to resolve this- I think it’s a bit naive of me to automatically send the code along no matter what the situation- right now we automatically send the code under known circumstances.
I was just looking at this- i’m not sure this is possible with the API that the envisalink provides us. There is a keypress command- just not sure what keypress it would be. There doesn’t seem to be a command for PGM1-4 that i can send.
But this function exists in the Eyezon web interface, you can fill in your code and toggle a PGM from the dropdown list. How does that differs from how the HA uses this API?
Am also looking for a solution to activate PGMs from within HA both with and without codes.
The API is indeed different than the website See below.
http://forum.eyez-on.com/FORUM/viewtopic.php?t=301
After some searching in the forums, i guess the PGM functions are referred to as “Command Outputs” in the documentation- so they didn’t jump out at me at first.
Also, and this is a bit embarassing, but turns out that the stub code to send these commands already exists within the pyenvisalink library . I do see an issue with it though that will need correction.
So really the issue becomes how do we want to represent this within HASS- the definitions of available services are defined at the component level, and this is not necessarily valid for other alarms- only envisalink. I’m leaning towards exposing this as “switch” components that activate the PGMs when the switch.turn_on is called. This is similar to how I’ve done the other pieces of this (this zone sensors, etc).
Having now used the script I put in place that essentially sends the commands in two sets for a week or so I think the method of just sending two sets of keypresses (one to toggle the PGM and another to send the code) works fine. The script has worked without issue every time I use it and under normal circumstances, I’m not sitting watching the log, so I don’t even notice the error when the envisalink initially asks for the code.
If you’re planning for a more integrated way to toggle PGMs, at least for the way I use them (to open/close my garage door), I would just like the ability to add a button/switch that provided the functionality to toggle the PGMs. There would need to be some way to let the plugin know how many buttons to display though since people may have varying numbers of them hooked up (or none at all).
Thanks for your excellent work Cinntax!
Thanks- yeah I actually did have some time last night to look at this, and the way I’m thinking of doing this is through a custom service- and you can wire up any switch or logic you’d like to that. It’d handle the code and everything too. How does that sound? The service would take in the Pgm number as well as the partition number.
@rhatguy Here is the pull request: https://github.com/home-assistant/home-assistant/pull/19499
I’ll reach out again once it’s in dev- i don’t have a DSC panel, so I can’t really test the new service. Perhaps you can test?
Absolutely. I’m fairly new to HA, but have a good linux/scripting background and happy to help test. Would I just need to join the beta channel in Hass.io to get the new code to test once its available or is there a better way to test?
Sure- the best way to do this is to follow the instructions at: https://developers.home-assistant.io/docs/en/development_index.html to setup a development instance of HA. Then with git, you can pull the dev (https://github.com/home-assistant/home-assistant.git) branch. The only thing is that i’m having some struggles getting my changes commited. Some tests are failing that are unrelated to my changes (or at least i think so). So i’m having a conversation with the reviewers to see what I need to do to get my change merged in.
any documentation on the use of the pgm commit on github?
Yeah along with the commit for the change, I have a commit going through on the homeassistant.io page. If you pull the dev branch, there will be a new service called “envisalink.invoke_custom_function”. The parameters for it would look like this:
{
"partition": "1" <<Or whatever partition you're callign against- typically people just use partition 1>>
"pgm": "1" <<The number of PGM to call (1-4)>>
}
Just a note that this change is now in the dev branch- so this can now be tested. I do have an additional fix to make to be fully compliant with the standards, but it should at least work at this point.
Does this work the other way around? allowing the user to trigger PGM 1-4 to integrate in automations? or am i reading the above wrong?
That’s correct- if, in an automation, one of the steps could be to call this custom service, enabling the pgm to be triggered by Ha.
I understand that we can trigger pgm 1-4 from automations for example if button pressed then pgm 1
But in HomeSeer automation we used to use the touchscreen for our alarm which had PGM 1-4 and when we pressed the button it could then run an entire event/scene on HomeSeer for example… almost like an additional remote control.
Ahh I see- hmm… well right now i’m definitely only going the other way (HA -> PGM on envisalink).
I don’t have a DSC panel to check, but I only see one command in the API documentation that might work for this, and it’s the command that the envisalink uses to challenge us for the security code.
So right now the flow goes like this:
- Send a command to evl to trigger PGM
- evl challenges us for the code (and says which PGM it’s for)
- we respond with the code.
I wonder if maybe if you hit the PGM directly on the unit that it will challenge us for the code…
Would it be possible to add logger:
to your configuration.yaml, and post debug logs? Just run in debug mode, and press the PGM on the unit.
I’ve been experiencing an issue with my DSC integration and wondered if anyone had seen this before. I have home assistant connecting to an android phone running Mike P’s excellent dscserver (which emulates an EVL but allows multiple connections). After some period of time I’ve noticed that my HA box seems to no longer get updates about zones opening and closing and it is also unable to send new commands to arm/disarm the alarm. The phone and my other apps that communicate with it are still functional and upon a reboot of HA, it reconnects and starts working again.
Today I caught the error in the HA logs and it seems that the connection to the dscserver phone is down and it isn’t trying to reestablish the connection. My configuration.yaml as well as the log that happens when I try to arm the alarm in this state is pasted below. Am I missing something in the configuration or is there some way to detect that the connection is gone and reconnect? I could probably mask the issue with a nightly reboot of HA, but I don’t want to do that.
envisalink:
host: dscserver.XXXX.com
panel_type: DSC
user_name: XXXX
password: XXXX
code: ‘XXXX’
port: 4025
evl_version: 3
keepalive_interval: 60
zonedump_interval: 0
panic_type: Police
zones:
2019-02-21 11:28:52 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 289, in _handle_service_platform_call
await getattr(entity, func)(**data)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/alarm_control_panel/envisalink.py”, line 144, in async_alarm_arm_home
str(self._code), self._partition_number)
File “/usr/local/lib/python3.6/site-packages/pyenvisalink/alarm_panel.py”, line 231, in arm_stay_partition
self._client.arm_stay_partition(code, partitionNumber)
File “/usr/local/lib/python3.6/site-packages/pyenvisalink/dsc_client.py”, line 53, in arm_stay_partition
self.send_command(evl_Commands[‘ArmStay’], str(partitionNumber))
File “/usr/local/lib/python3.6/site-packages/pyenvisalink/dsc_client.py”, line 26, in send_command
self.send_data(to_send)
File “/usr/local/lib/python3.6/site-packages/pyenvisalink/envisalink_base_client.py”, line 102, in send_data
self._transport.write((data + ‘\r\n’).encode(‘ascii’))
File “uvloop/handles/stream.pyx”, line 671, in uvloop.loop.UVStream.write
File “uvloop/handles/handle.pyx”, line 159, in uvloop.loop.UVHandle._ensure_alive
RuntimeError: unable to perform operation on <TCPTransport closed=True reading=False 0x736c99e0>; the handler is closed
Strange- so the pyenvisalink library does use an asyncio protocol to do the network connection, which does have connection lost/reconnection logic built in. So with the exception of the very initial connection upon hass startup, we will indeed attempt to reconnect upon a lost connection.
I think the best action to take here would be to catch the error you show here, and force a reconnect on my end.
Is this something you can reproduce/test for me if I make the change?