davesmeghead / visonic

Visonic Custom Component for integration with Home Assistant
Apache License 2.0
92 stars 20 forks source link

Merge request - M5Stack ESP32 Ethernet Unit with PoE #108

Closed rjpearce closed 7 months ago

rjpearce commented 8 months ago

Thank you for this amazing project.

I have managed to get this working on a M5Stack ESP32 Ethernet Unit with PoE based another awesome project. This gives people the option of having a hardwired connection rather than Wifi.

What is best way for me to update the documentation, shall I add markdown in this ticket so you can copy it up?

Thanks -Richard

davesmeghead commented 8 months ago

Hi and thanks for the contribution, another way of doing a wired ethernet connection is always welcome, especially a PoE as that's new. The best and easiest way I think is as you suggest and to attach the markdown file(s) as a post in this issue. Thanks again

rjpearce commented 8 months ago

Using-M5Stack-ESP32-Ethernet-Unit-with-POE-M5Unit-PoESP32.md

Photos: PXL_20240401_102223863 MP PXL_20240401_102212106 MP PXL_20240401_102158959 MP IMG_3052.jpeg

EyalRotem commented 8 months ago

Just wanted to say that this is pretty neat!

davesmeghead commented 7 months ago

I agree, looks good.
I have uploaded the files to github so you should be able to see it from the wiki under hardware setup (as the 4th example). https://github.com/davesmeghead/visonic/wiki/Hardware-Setup

The 3 images didn't work from the list so I screen grabbed them, added them in to the MD file and uploaded it and the images, I played around with the image size as well, if they aren't to your liking then just let me know what you want doing.

davesmeghead commented 7 months ago

If you're still looking at this issue, can I ask you a favour to try something for me.

I've been looking at the protocol between a real Powerlink hardware device and a PowerMaster 30 panel. It negotiates the baud rate, and then changes the baud rate at a specific point in the protocol from 9600 to 38400. I'd like to mimic that and I have test code with a USB/RS232 connection but I was wondering what I can do with an Ethernet connection.

I'm in the process of trying it with ESPHome, much the same as your hardware device but using a Wemos D1 R2. I have not altered my integration software yet to support any of this, it is all test code at the moment so it is early days.

I would appreciate you trying this in your ESPHome config file. Note that in the select it uses the id of the uart uart_bus_visonic so if you have a different name please update it (I have only included the relevant part of the uart settings, just to show you that it is named uart_bus_visonic).

This should create a select entity in Home Assistant called select.visonic_baud_rate as it takes the name from the select. You should be able to select either 9600 or 38400 in the options in Home Assistant.

uart:
  id: uart_bus_visonic
# and the rest of the uart settings

# The following select allows the baud rate to be changed, it creates a select entity in Home Assistant
select:
  - id: change_baud_rate
    name: Visonic Baud rate
    platform: template
    options:
      - "9600"
      - "38400"
    initial_option: "9600"
    optimistic: true
    restore_value: True
    internal: false
    entity_category: config
    icon: mdi:swap-horizontal
    set_action:
      - lambda: |-
          id(uart_bus_visonic).flush();
          uint32_t new_baud_rate = stoi(x);
          ESP_LOGD("change_baud_rate", "Changing baud rate from %i to %i",id(uart_bus_visonic).get_baud_rate(), new_baud_rate);
          if (id(uart_bus_visonic).get_baud_rate() != new_baud_rate) {
            id(uart_bus_visonic).set_baud_rate(new_baud_rate);
            id(uart_bus_visonic).load_settings();
          }

Don't worry if you don't have time to do this, like I said it's early days and I'm not sure whether this capability will progress in to the Integration, it's just something I'm experimenting with. It is also only for PowerMaster panels, all PowerMax panels seem to be fixed at 9600 baud anyway.

I'm doing this for 2 reasons. The first is that some PowerMaster users have had problems setting the baud rate and secondly, it seems that the PowerMaster only sends a complete image from a CameraPIR when it's 38400 baud. As I said, early days! And this would only be supported on Ethernet when using ESPHome.

rjpearce commented 7 months ago

I agree, looks good. I have uploaded the files to github so you should be able to see it from the wiki under hardware setup (as the 4th example). https://github.com/davesmeghead/visonic/wiki/Hardware-Setup

The 3 images didn't work from the list so I screen grabbed them, added them in to the MD file and uploaded it and the images, I played around with the image size as well, if they aren't to your liking then just let me know what you want doing.

Looks great!

rjpearce commented 7 months ago

If you're still looking at this issue, can I ask you a favour to try something for me.

I've been looking at the protocol between a real Powerlink hardware device and a PowerMaster 30 panel. It negotiates the baud rate, and then changes the baud rate at a specific point in the protocol from 9600 to 38400. I'd like to mimic that and I have test code with a USB/RS232 connection but I was wondering what I can do with an Ethernet connection.

I'm in the process of trying it with ESPHome, much the same as your hardware device but using a Wemos D1 R2. I have not altered my integration software yet to support any of this, it is all test code at the moment so it is early days.

I would appreciate you trying this in your ESPHome config file. Note that in the select it uses the id of the uart uart_bus_visonic so if you have a different name please update it (I have only included the relevant part of the uart settings, just to show you that it is named uart_bus_visonic).

This should create a select entity in Home Assistant called select.visonic_baud_rate as it takes the name from the select. You should be able to select either 9600 or 38400 in the options in Home Assistant.

uart:
  id: uart_bus_visonic
# and the rest of the uart settings

# The following select allows the baud rate to be changed, it creates a select entity in Home Assistant
select:
  - id: change_baud_rate
    name: Visonic Baud rate
    platform: template
    options:
      - "9600"
      - "38400"
    initial_option: "9600"
    optimistic: true
    restore_value: True
    internal: false
    entity_category: config
    icon: mdi:swap-horizontal
    set_action:
      - lambda: |-
          id(uart_bus_visonic).flush();
          uint32_t new_baud_rate = stoi(x);
          ESP_LOGD("change_baud_rate", "Changing baud rate from %i to %i",id(uart_bus_visonic).get_baud_rate(), new_baud_rate);
          if (id(uart_bus_visonic).get_baud_rate() != new_baud_rate) {
            id(uart_bus_visonic).set_baud_rate(new_baud_rate);
            id(uart_bus_visonic).load_settings();
          }

Don't worry if you don't have time to do this, like I said it's early days and I'm not sure whether this capability will progress in to the Integration, it's just something I'm experimenting with. It is also only for PowerMaster panels, all PowerMax panels seem to be fixed at 9600 baud anyway.

I'm doing this for 2 reasons. The first is that some PowerMaster users have had problems setting the baud rate and secondly, it seems that the PowerMaster only sends a complete image from a CameraPIR when it's 38400 baud. As I said, early days! And this would only be supported on Ethernet when using ESPHome.

Yes no problem, more than happy to help I will give this a try later and report back.

rjpearce commented 7 months ago

@davesmeghead hopefully this is helpful:

For reference my device is detected as a PowerMax Complete Part I updated the device and gave it some time to get setup. A few minutes later I changed the baud rate.

# 38400
[13:32:39][D][select:062]: 'Visonic Baud rate' - Setting
[13:32:39][D][select:115]: 'Visonic Baud rate' - Set selected option to: 38400
[13:32:39][D][change_baud_rate:062]: Changing baud rate from 9600 to 38400
[13:32:39][C][uart.arduino_esp32:131]: UART 0 was reloaded.
[13:32:39][C][uart.arduino_esp32:137]: UART Bus 0:
[13:32:39][C][uart.arduino_esp32:138]:   TX Pin: GPIO17
[13:32:39][C][uart.arduino_esp32:139]:   RX Pin: GPIO16
[13:32:39][C][uart.arduino_esp32:141]:   RX Buffer Size: 256
[13:32:39][C][uart.arduino_esp32:143]:   Baud Rate: 38400 baud
[13:32:39][C][uart.arduino_esp32:144]:   Data Bits: 8
[13:32:39][C][uart.arduino_esp32:145]:   Parity: NONE
[13:32:39][C][uart.arduino_esp32:146]:   Stop bits: 1
[13:32:39][D][select:015]: 'Visonic Baud rate': Sending state 38400 (index 1)
[13:32:58][D][uart_debug:114]: >>> 0D:AB:0E:00:17:1E:00:03:03:01:04:00:43:C2:0A
[13:33:01][D][uart_debug:114]: <<< F8:F8:F8:80:80:80:80:F8:F8:80:F8:80:80
[13:33:01][D][esp32.preferences:114]: Saving 1 preferences to flash...
[13:33:01][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[13:33:08][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:33:11][D][uart_debug:114]: <<< F8:F8:F8:80:80:80:80:F8:F8:80:F8:80:80
[13:33:18][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:33:21][D][uart_debug:114]: <<< F8:F8:F8:80:80:80:80:F8:F8:80:F8:80:80
[13:33:28][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:33:31][D][uart_debug:114]: <<< F8:F8:F8:80:80:80:80:F8:F8:80:F8:80:80
[13:33:38][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:33:41][D][uart_debug:114]: <<< F8:F8:F8:80:80:80:80:F8:F8:80:F8:80:80
[13:33:48][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:33:58][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:34:08][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:34:18][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:34:28][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:34:38][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A

It looked like it stopped getting replies.

I tried a second time and the output was identical. It continues to send 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A but receives no reply.

Flipping the baud back to 9600 makes it work again.

I thought I would try some other baud rates:

# 28800
[13:50:33][D][select:062]: 'Visonic Baud rate' - Setting
[13:50:33][D][select:115]: 'Visonic Baud rate' - Set selected option to: 28800
[13:50:33][D][change_baud_rate:065]: Changing baud rate from 9600 to 28800
[13:50:33][C][uart.arduino_esp32:131]: UART 0 was reloaded.
[13:50:33][C][uart.arduino_esp32:137]: UART Bus 0:
[13:50:33][C][uart.arduino_esp32:138]:   TX Pin: GPIO17
[13:50:33][C][uart.arduino_esp32:139]:   RX Pin: GPIO16
[13:50:33][C][uart.arduino_esp32:141]:   RX Buffer Size: 256
[13:50:33][C][uart.arduino_esp32:143]:   Baud Rate: 28800 baud
[13:50:33][C][uart.arduino_esp32:144]:   Data Bits: 8
[13:50:33][C][uart.arduino_esp32:145]:   Parity: NONE
[13:50:33][C][uart.arduino_esp32:146]:   Stop bits: 1
[13:50:33][D][select:015]: 'Visonic Baud rate': Sending state 28800 (index 2)
[13:50:33][D][uart_debug:114]: >>> 0D:02:FD:0A
[13:50:33][D][uart_debug:114]: >>> 0D:02:FD:0A
[13:50:58][D][uart_debug:114]: >>> 0D:AB:0E:00:17:1E:00:03:03:01:04:00:43:C2:0A
[13:51:01][D][uart_debug:114]: <<< 1C:1C:E0:00:1C
[13:51:08][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:51:10][D][uart_debug:114]: <<< 1C:1C:E0:00:1C
[13:51:18][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:51:20][D][uart_debug:114]: <<< 1C:1C:E0:00:1C
[13:51:28][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:51:29][D][esp32.preferences:114]: Saving 1 preferences to flash...
[13:51:29][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[13:51:31][D][uart_debug:114]: <<< 1C:1C:E0:00:1C
[13:51:38][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:51:41][D][uart_debug:114]: <<< 1C:1C:E0:00:1C
[13:51:48][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[13:51:58][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
# 19200
[14:00:24][D][change_baud_rate:065]: Changing baud rate from 9600 to 19200
[14:00:24][C][uart.arduino_esp32:131]: UART 0 was reloaded.
[14:00:24][C][uart.arduino_esp32:137]: UART Bus 0:
[14:00:24][C][uart.arduino_esp32:138]:   TX Pin: GPIO17
[14:00:24][C][uart.arduino_esp32:139]:   RX Pin: GPIO16
[14:00:24][C][uart.arduino_esp32:141]:   RX Buffer Size: 256
[14:00:24][C][uart.arduino_esp32:143]:   Baud Rate: 19200 baud
[14:00:24][C][uart.arduino_esp32:144]:   Data Bits: 8
[14:00:24][C][uart.arduino_esp32:145]:   Parity: NONE
[14:00:24][C][uart.arduino_esp32:146]:   Stop bits: 1
[14:00:24][D][select:015]: 'Visonic Baud rate': Sending state 19200 (index 1)
[14:00:38][D][uart_debug:114]: >>> 0D:AB:0E:00:17:1E:00:03:03:01:04:00:43:C2:0A
[14:00:39][I][ota:117]: Boot seems successful, resetting boot loop counter.
[14:00:39][D][esp32.preferences:114]: Saving 2 preferences to flash...
[14:00:39][D][esp32.preferences:143]: Saving 2 preferences to flash: 0 cached, 2 written, 0 failed
[14:00:43][D][uart_debug:114]: <<< E6:80:9E:E6:F8:86:98:86:98:80
[14:00:48][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:00:53][D][uart_debug:114]: <<< E6:80:9E:E6:F8:86:98:86:98:80
[14:00:58][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:01:03][D][uart_debug:114]: <<< E6:80:9E:E6:F8:86:98:86:98:80
[14:01:08][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:01:13][D][uart_debug:114]: <<< E6:80:9E:E6:F8:86:98:86:98:80
[14:01:18][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:01:23][D][uart_debug:114]: <<< E6:80:9E:E6:F8:86:98:86:98:80
[14:01:28][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:01:38][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:01:48][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:01:58][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A
[14:02:08][D][uart_debug:114]: >>> 0D:A2:00:00:00:00:00:00:00:00:00:00:43:1A:0A

And the rather curious but accidental (I messed up the initial_option in the select) changing the baud from 9600 to 9600

[13:57:59][D][select:062]: 'Visonic Baud rate' - Setting
[13:57:59][D][select:115]: 'Visonic Baud rate' - Set selected option to: 9600
[13:57:59][D][change_baud_rate:065]: Changing baud rate from 9600 to 9600
[13:57:59][D][select:015]: 'Visonic Baud rate': Sending state 9600 (index 0)
[13:58:09][D][uart_debug:114]: >>> 0D:AB:0E:00:17:1E:00:03:03:01:04:00:43:C2:0A
[13:58:09][D][uart_debug:114]: <<< 0D:02:43:BA:0A
[13:58:14][D][uart_debug:114]: <<< 0D:AB:03:00:1E:00:31:2E:30:37:00:00:43:29:0A
[13:58:14][D][uart_debug:114]: >>> 0D:02:43:BA:0A
[13:58:14][D][uart_debug:114]: >>> 0D:AB:0E:00:17:1E:00:03:03:01:04:00:43:C2:0A
[13:58:14][D][uart_debug:114]: <<< 0D:02:43:BA:0A
[13:58:23][D][esp32.preferences:114]: Saving 1 preferences to flash...
[13:58:23][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[13:58:39][D][uart_debug:114]: >>> 0D:A2:00:00:20:00:00:00:00:00:00:00:43:F9:0A
[13:58:39][D][uart_debug:114]: <<< 0D:02:43:BA:0A:0D:A5:00:06:0F:00:00:00:00:00:00:00:43:02:0A
[13:58:39][D][uart_debug:114]: >>> 0D:02:FD:0A
[13:58:44][D][uart_debug:114]: <<< 0D:AB:03:00:1E:00:31:2E:30:37:00:00:43:29:0A
[13:58:44][D][uart_debug:114]: >>> 0D:02:43:BA:0A
[13:58:44][D][uart_debug:114]: >>> 0D:AB:0E:00:17:1E:00:03:03:01:04:00:43:C2:0A
[13:58:44][D][uart_debug:114]: <<< 0D:02:43:BA:0A

Let me know if there is something else to try. Also let me know if I should be redacting any of this output.

davesmeghead commented 7 months ago

It's really helpful thankyou, you've shown me that the ESPHome baud change works and people other than me can set it up and use it.

I wouldn't expect the panel to respond to anything other than 9600 baud at the moment as you'd need to send the "baud change" message to the panel first (just before changing the baud). I already do this in my test setup with my PowerMaster 30, although with the ethernet test I manually change the baud using the select and the service at the moment and not from the integration python itself, it's a work in progress. I have it working with a USB connection, it auto-negotiates the baud rate between integration and panel.

I'm not sure that PowerMax panels respond to the "change baud" message, as I said, a work in progress. It's a "B0" message and my experience tells me that only PowerMaster panels respond to this message type. I'm in the process of buying a cheap PowerMax panel off Ebay to give it a try as I don't want to mess about with my house panel.

If I get it working with the PowerMax, and it's more robust than it is now, then I might ask you to give it a try if that's OK.

There is no need to redact anything, I've taken a look through and there's no panel codes in any of those messages.

rjpearce commented 7 months ago

Glad it was helpful. Sure let me know if there is anything more I can do to help. Did you want to close this ticket and message/email me ?

davesmeghead commented 7 months ago

Yes we may as well close this ticket, thanks again