deiger / Alarm

Code to connect and control alarms by PIMA.
GNU General Public License v3.0
17 stars 11 forks source link

Not getting any reading from raspberry pi serial #12

Open l1c2d3 opened 3 years ago

l1c2d3 commented 3 years ago

Hi @deiger ,

I followed the instructions and I´m not getting any reading via serial, not even garbage. Is there an special firmware version required? My panel is a PIMA HUNTER 896 with firmware version HP896-ES-es Rev. 6.08

Given the voltage difference between the raspberry pi and the tx/rx pins from the panel, I even tried with a logic shift converter circuit, but still the same luck.

I even tried yeudas solution based on your work using an esp8266 instead of a raspberry pi, but I couldn't get any serial reading with it.

Any help would be much appreciated.

Thanks in advance.

Jens-Wymeersch commented 3 years ago

@l1c2d3 did you ever get it to work ? If so, could you please share what you have done ? I have also a HP896

l1c2d3 commented 3 years ago

@l1c2d3 did you ever get it to work ? If so, could you please share what you have done ? I have also a HP896

No, I couldn't figure it out, so I abandoned it for the time being. I came to conclusion that it is firmware related (I have an old version), but being unable to try another version, since I haven't found an updated firmware version chip online.

Hope you have better luck, and if so, please share. So will I, once I get back to work on that project. I will hook up my computer with a serial adapter.

Jens-Wymeersch commented 3 years ago

@l1c2d3 I talked to PIMA last week, and they told me that HP896 was too old and most probably wouldn't work. I've now noticed that in the documentation of the PIMA Home Automation Kit, the version of the controller is not RXN410 instead of RXN400 which I have. My assumption is that in order for this to work, I need to upgrade. I'm going to call them again to examine if my assumption is correct and see how much this would cost. I'll keep you posted. Please also have a look from your side, we might be able to negotiate if we join forces. Living in Modi'in by the way.

maorcc commented 3 years ago

I have a PI Zero connected directly to the PIMA board serial connector. Works fine for a long time now. image

Jens-Wymeersch commented 3 years ago

@maorcc thank you for sharing your wiring. I'll give it another go today. Another few questions :

Jens-Wymeersch commented 3 years ago

@maorcc The test command looks something like : python3 ./pima_server.py --port 7777 --key 28e6db84-44a4-410b-8f58-8c2275fdd396 --zones 96 --login 000000 --serialport /dev/serial0 --mqtt_host XX.YY.ZZ.UU but it doesn't do anything. Can you please get your take on this ?

deiger commented 3 years ago

@Jens-Wymeersch maybe it is a different serial port? Could you try listing the ports, by ls -l /dev/serial/by-id?

Jens-Wymeersch commented 3 years ago

@deiger I'm getting the following image

deiger commented 3 years ago

According to all the documentation I could find on the web, you should be connecting pins 6, 8, 10. Maybe you need to enable the UART? See "Disable Linux serial console" here.

Jens-Wymeersch commented 3 years ago

@deiger I've enabled the UART as described in the document you send. I've connected the cables to the USB to TTL adapter and get the following (setting it at 3.3V instead of 5V)

image

I used then the command as follows : python3 ./pima_server.py --port 7777 --key 28e6db84-44a4-410b-8f58-8c2275fdd396 --zones 96 --login 000000 --serialport /dev/ttyUSB0 --mqtt_host XX.YY.ZZ.UU --log_level DEBUG

The program starts but in the browser on XX.YY.ZZ.UU:7777 nothing happens nor do I see anything on MQTT.

Here is what you can see in the log Feb 1 21:41:35 raspberrypi D0201 21:41:35.082 pima_server.py:65] Port: /dev/ttyUSB0. Feb 1 21:42:39 raspberrypi dockerd[557]: time="2021-02-01T21:42:39.734881553+02:00" level=info msg="ignoring event" container=bae1c760dd2d4f744e34994d7fd58d9:

deiger commented 3 years ago

You don't need to connect the power pin at all. It serves to power the connected device, but the Alarm has a separate power source. Try running it in docker:

  1. Create the following config file in /opt/pima/options.json
    {
    "log_level": "INFO",
    "login": "000000",
    "zones": "96",
    "mqtt_discovery_max_zone": 30,
    "mqtt_host": "XX.YY.ZZ.UU",
    "key": "28e6db84-44a4-410b-8f58-8c2275fdd396",
    "port": 7777,
    "mqtt_user": "homeassistant",
    "mqtt_pass": "password",
    "serialport": "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0"
    }
  2. Run:
    sudo docker run -d --name pima --log-driver journald --restart always -v /opt/pima:/data deiger/pima:0.7.1.6

    The logs will be available in:

    journalctl CONTAINER_NAME=pima
Jens-Wymeersch commented 3 years ago

Hi Dror,

Thank you for your quick reply. I got the container working with no errors initially but within the running container, it still have trouble with the serial connection it seems.

Here you have the error message in Portainer :

Traceback (most recent call last):,
  File "pima_server.py", line 85, in __init__,
    self._create_alarm(),
  File "pima_server.py", line 139, in _create_alarm,
    self._alarm = pima.Alarm(*self._alarm_args)  # type: pima.Alarm,
  File "/app/pima.py", line 146, in __init__,
    raise Error('Failed to connect to serial port.') from e,
pima.Error: Failed to connect to serial port.,
E0202 13:31:58.396  pima_server.py:87] Failed to create alarm object.,
Traceback (most recent call last):,
  File "/usr/local/lib/python3.7/site-packages/pyserial-3.5-py3.7.egg/serial/serialposix.py", line 322, in open,
    self.fd = os.open(self.portstr, os.O_RDWR | os.O_NOCTTY | os.O_NONBLOCK),
FileNotFoundError: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0',
During handling of the above exception, another exception occurred:,
Traceback (most recent call last):,
  File "/app/pima.py", line 143, in __init__,
    timeout=1),
  File "/usr/local/lib/python3.7/site-packages/pyserial-3.5-py3.7.egg/serial/serialutil.py", line 244, in __init__,
    self.open(),
  File "/usr/local/lib/python3.7/site-packages/pyserial-3.5-py3.7.egg/serial/serialposix.py", line 325, in open,
    raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)),
serial.serialutil.SerialException: [Errno 2] could not open port /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0: [Errno 2] No such file or directory: '/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50285BI-if00-port0',
The above exception was the direct cause of the following exception:,

And here you find the error output from journalctl

Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: During handling of the above exception, another excep Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: Traceback (most recent call last): Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: File "/app/pima.py", line 143, in init Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: timeout=1) Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: File "/usr/local/lib/python3.7/site-packages/pyseri Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: self.open() Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: File "/usr/local/lib/python3.7/site-packages/pyseri Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: raise SerialException(msg.errno, "could not open Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: serial.serialutil.SerialException: [Errno 2] could no Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: The above exception was the direct cause of the follo Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: Traceback (most recent call last): Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: File "pima_server.py", line 85, in init Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: self._create_alarm() Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: File "pima_server.py", line 139, in _create_alarm Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: self._alarm = pima.Alarm(*self._alarm_args) # ty Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: File "/app/pima.py", line 146, in init Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: raise Error('Failed to connect to serial port.') Feb 02 15:19:39 raspberrypi 9826ee42b554[557]: pima.Error: Failed to connect to serial port. Feb 02 15:20:41 raspberrypi 9826ee42b554[557]: E0202 13:20:41.243 pima_server.py:87] Failed to crea Feb 02 15:20:41 raspberrypi 9826ee42b554[557]: Traceback (most recent call last): Feb 02 15:20:41 raspberrypi 9826ee42b554[557]: File "/usr/local/lib/python3.7/site-packages/pyseri Feb 02 15:20:41 raspberrypi 9826ee42b554[557]: self.fd = os.open(self.portstr, os.ORDWR | os.O Feb 02 15:20:41 raspberrypi 9826ee42b554[557]: FileNotFoundError: [Errno 2] No such file or director

deiger commented 3 years ago

Right, we need to map the serial port as well:

sudo docker run -d --name pima --log-driver journald --restart always -v /opt/pima:/data --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0:/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0 deiger/pima:0.7.1.6
deiger commented 3 years ago

Alternatively you can do:

sudo docker run -d --name pima --log-driver journald --restart always -v /opt/pima:/data --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0:/dev/serial deiger/pima:0.7.1.6

And then set the port in the options file to /dev/serial.

Jens-Wymeersch commented 3 years ago
```shell
sudo docker run -d --name pima --log-driver journald --restart always -v /opt/pima:/data --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0:/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0 deiger/pima:0.7.1.6

I ran this one. No logs found in Portainer nor in journald but on the other hand I don't see anything in MQTT neither.

Jens-Wymeersch commented 3 years ago

sudo docker run -d --name pima --log-driver journald --restart always -v /opt/pima:/data --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0:/dev/serial deiger/pima:0.7.1.6

@deiger same result - no errors any more but also no entry in MQTT.

deiger commented 3 years ago

Hmm... Try changing the log_level in options.json to DEBUG. It seems strange that you won't see anything in journalctl.

Jens-Wymeersch commented 3 years ago

@deiger this is what I get Feb 02 21:29:02 raspberrypi 376990f53ad7[557]: D0202 19:29:02.900 pima_server.py:70] Port: /dev/serial.

deiger commented 3 years ago

Are you sure the serial port is enabled in the Alarm? You are supposed to have a lot of data flowing in.

Jens-Wymeersch commented 3 years ago

@deiger I toggled on the controller the first L from - to + and entr'ed. I moved the tx and rx cable, and we got lifted off it seems. I also see an entry in my MQTT. That said, I followed the drawing to the letter, but it seems it never hurts to switch. Can you please guide me to the next step ?

deiger commented 3 years ago

RX should be connected to TX and vice versa, I believe that is stated in the diagram. If it works, then that's it. Change the log_level back to INFO, and see that your alarm appears in HA. The docker command should maintain it alive through restarts.

Jens-Wymeersch commented 3 years ago

@deiger what do you mean with

Change the log_level back to INFO, and see that your alarm appears in HA.
The docker command should maintain it alive through restarts.

Should I change the options.json file, delete the current docker image/container and re-build them ? PS I see already see an entry in HA/mosquitto

deiger commented 3 years ago

You don't need to delete the container. Just update the config file, and restart the container, so it will pick up the new value.

Jens-Wymeersch commented 3 years ago

@deiger Thank you for all the work. I got the items in HA. A few remaining questions I got the following card : image

Jens-Wymeersch commented 3 years ago

@deiger when I put ARM AWAY - it sets off the alarm (sirene is heard, etc.)

deiger commented 3 years ago

Arm Away does full arm, like a long press on 1. Arm Home arms home 1, like a long press on 4.

Jens-Wymeersch commented 3 years ago

@deiger we typically use 7 to arm our house. I suppose commands 1 and 4 is something set by the alarm company. Right ?

deiger commented 3 years ago

7 is Home 2. The server supports it, but HA supports only one Arm Home, and since typically Home 1 is used and Home 2 isn't, I mapped Arm Home to Home 1. You can either change the mapping code, or change your alarm's configuration. Since you have the Technician code, you can do the latter.

Jens-Wymeersch commented 3 years ago

thanks @deiger Something happened in the meanwhile. I see the following message on MQTT 1612347775: Client auto-7F398332-7F0C-F910-45C7-C4C96CD4AB33 has exceeded timeout, disconnecting. Any reason why this happened and how I can avoid it for the future ?

deiger commented 3 years ago

Not sure, anything appeared in parallel in the logs of the container?

Jens-Wymeersch commented 3 years ago

@deiger Since then everything has run as expected. I've restarted Mosquitto and the container. Thank you again for all the hard work and helping through the hoops.

Jens-Wymeersch commented 3 years ago

@deiger it's been running stable since. One last question, if during a break-in the alarm goes off, will I somehow be alerted as well via the system. If so, how ?

deiger commented 3 years ago

There are two effects to an alarm being set off:

  1. The relevant sensor starts alarming.
  2. In the recent version (0.7.2.3) the outputs for the external and internal siren (1 and 2) will be set, and this would result in a state change to "triggered".
Jens-Wymeersch commented 3 years ago

@deiger As I've just installed the system, I assume that I have the latest version correct ?

deiger commented 3 years ago

The last update was yesterday, so that depends. If you're using the HA add-on, it should show the current version at the top of the add on page. You can also see all the version by running:

docker ps -a
Jens-Wymeersch commented 3 years ago

I'm running it seems deiger/pima:0.7.1.6. So I guess I'll need to remove the current version and redo the installation procedure for the next. Right ?

l1c2d3 commented 3 years ago

@Jens-Wymeersch sorry, not writting back to you, I fell ill with covid. Fully recovered now. Glad, you had the help you needed. I got back to work today with the raspberry pi and the alarm, and my problem was, that I forgot to re-enable uart after formatting the sd card. The help you got, made me realized that today.

@deiger My motion sensors wired and wireless are not updating (state is always off), do they have to be configured in a different way than a door/window sensor? Door/window sensors work fine. I have 1 wired motion sensor, not updating. I have some other connected via pima wireless expander, and I added them manually in HA, not updating either.

(This is an example of one of my motion sensors)

Jens-Wymeersch commented 3 years ago

@deiger I've reinstalled the docker to the new version following the same commands as previously but get now following error message in portainer Traceback (most recent call last):, E0207 07:36:06.484 pima_server.py:87] Failed to create alarm object., Traceback (most recent call last):, File "/app/pima.py", line 145, in __init__, timeout=1), File "/usr/local/lib/python3.7/site-packages/pyserial-3.5-py3.7.egg/serial/serialutil.py", line 244, in __init__, self.open(), File "/usr/local/lib/python3.7/site-packages/pyserial-3.5-py3.7.egg/serial/serialposix.py", line 325, in open, raise SerialException(msg.errno, "could not open port {}: {}".format(self._port, msg)), serial.serialutil.SerialException: [Errno 21] could not open port /dev/serial: [Errno 21] Is a directory: '/dev/serial'

deiger commented 3 years ago

@Jens-Wymeersch are you mapping /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0, per this? Do you see usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0 in ls -l /dev/serial/by-id?

deiger commented 3 years ago

@l1c2d3 they work exactly the same. All the currently live sensors should appear in pima_alarm/status, under "open zones". Note that it takes a few seconds for the sensor to update its status (due to hardware limitations). One thing that I did find useful is to customize the sensors, setting a different device_class in customize.yaml.

Jens-Wymeersch commented 3 years ago

@deiger I'm mapping it like this (https://github.com/deiger/Alarm/issues/12#issuecomment-771704470).
I see the USB device with command ls -l /dev/serial/by-id and the previous version works perfectly with this (https://github.com/deiger/Alarm/issues/12#issuecomment-771704470). So something changed btw the versions. I tried without the mapping as (https://github.com/deiger/Alarm/issues/12#issuecomment-771704470) but this resulted in the same error we got before the mapping.

deiger commented 3 years ago

According to the error message /dev/serial is a directory. I suggest either use the first command I wrote (mounting to the inner directory), or change it to e.g. /dev/serialport (both in the mount command and in the options file).

deiger commented 3 years ago

Set /opt/pima/options.json to:

{
  "log_level": "INFO",
  "login": "000000",
  "zones": "96",
  "mqtt_discovery_max_zone": 30,
  "mqtt_host": "XX.YY.ZZ.UU",
  "key": "28e6db84-44a4-410b-8f58-8c2275fdd396",
  "port": 7777,
  "mqtt_user": "homeassistant",
  "mqtt_pass": "password",
  "serialport": "/dev/serialport"
}

Then run:

sudo docker run -d --name pima --log-driver journald --restart always -v /opt/pima:/data --device /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A50295BI-if00-port0:/dev/serialport deiger/pima:0.7.2.3
Jens-Wymeersch commented 3 years ago

@deiger Thank you for your quick reply and got a better answer still an error in the communication which i didn't have in the previous version.

`Traceback (most recent call last):

File "pima_server.py", line 104, in run

status = self._alarm.get_status()  # type: pima.Status

File "/app/pima.py", line 193, in get_status

raise Error('Invalid message {}.'.format(self._make_hex(response[2:3])))

pima.Error: Invalid message 0f.

I0207 17:10:13.211 pima_server.py:119] Trying to create the Alarm anew.

I0207 17:10:14.507 pima_server.py:152] Status: {'logged in': True, 'open zones': {3}, 'alarmed zones': set(), 'bypassed zones': set(), 'failed zones': set(), 'partitions': {1: 'disarm', 2: 'disarm', 3: 'disarm', 4: 'disarm', 5: 'disarm', 6: 'disarm', 7: 'disarm', 8: 'disarm', 9: 'disarm', 10: 'disarm', 11: 'disarm', 12: 'disarm', 13: 'disarm', 14: 'disarm', 15: 'disarm', 16: 'disarm'}, 'command ack': False}.

E0207 17:10:16.530 pima_server.py:111] Failed to get outputs status.

Traceback (most recent call last):

File "pima_server.py", line 109, in run

outputs = self._alarm.get_outputs()  # type: pima.Outputs

File "/app/pima.py", line 274, in get_outputs

raise Error('Invalid outputs response {}.'.format(self._make_hex(response)))

pima.Error: Invalid outputs response 08 0d 05 00 00 00 00 04 35.

E0207 17:10:26.340 pima_server.py:111] Failed to get outputs status.

Traceback (most recent call last):

File "pima_server.py", line 109, in run

outputs = self._alarm.get_outputs()  # type: pima.Outputs

File "/app/pima.py", line 274, in get_outputs

raise Error('Invalid outputs response {}.'.format(self._make_hex(response)))

pima.Error: Invalid outputs response 62 0d 05 01 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 35 03.

E0207 17:10:27.343 pima_server.py:116] Exception raised by Alarm.`

deiger commented 3 years ago

Hmm.. The fetching the outputs sometimes fails, and the response is of the system status, even on retry. The good news is that the error is only cluttering the logs, but otherwise ignored. I'll change the code to avoid the clutter, as it is unhelpful.

Jens-Wymeersch commented 3 years ago

@deiger Dror, You are amazing. Thank you for your quick reply. Should I move to the new version ?

deiger commented 3 years ago

You can, it's 0.7.2.4. The only difference is the log suppression.

Jens-Wymeersch commented 3 years ago

@deiger I'm going to leave it as is. Not really bothered with it as long as it doesn't interfere with the reading which you indicate it doesn't. I wonder what is the use case of the zones ? image

Which information should I get and at what time ?

deiger commented 3 years ago

For each zone you get 2 indicator sensors: open (i.e. an open window or motion sensed), and alarming (i.e. the zone triggered an alarm). As mentioned above, for the former you may wish to change the data_class for the open ones, to either door, window or motion, so you get the right symbols on open/close. Note that you'd better first rename the entities to something more human friendly.

Jens-Wymeersch commented 3 years ago

@deiger thanks. For those sensors, all are set as off and don’t change over time. Wired, wireless motion, door, window, etc. Will they only work in case of arm’ing of the system? for the device class, you indicate to change in customise.yaml ( I suppose this is in home assistant, right ?)