buxtronix / phev2mqtt

Mitsubishi PHEV to MQTT gateway
GNU General Public License v3.0
45 stars 15 forks source link

My20 issues #7

Open pszafer opened 3 years ago

pszafer commented 3 years ago

Hi, Thanks for this gateway. It's great! I have Outlander from 2020. I have several questions/requests, let me know if you'd like to divide them into separate issues.

martingjohn commented 3 years ago

On your last question - I switched over to using one of these https://linitx.com/product/mikrotik-routerboard-map-lite-wireless-access-point---rbmapl-2nd/14639 which I've set up to nat between the Outlander wifi and my normal lan. If you're interested in doing that I can share all the commands I used. And then I just set up a static route on my Hassio device to route through that gateway, I had quite a struggle with using the inbuilt wifi on my raspberry pi (both setup and stability), although getting the Mikrotik thing set up wasn't overly easy but has been very stable since.

pszafer commented 3 years ago

I will try with OpenWRT in that case, as I have one old router which should be capable of being wifi/lan bridge.

quenthal commented 3 years ago

On your last question - I switched over to using one of these https://linitx.com/product/mikrotik-routerboard-map-lite-wireless-access-point---rbmapl-2nd/14639 which I've set up to nat between the Outlander wifi and my normal lan. If you're interested in doing that I can share all the commands I used. And then I just set up a static route on my Hassio device to route through that gateway, I had quite a struggle with using the inbuilt wifi on my raspberry pi (both setup and stability), although getting the Mikrotik thing set up wasn't overly easy but has been very stable since.

I'm very intrested on that Mikrotik setup, one vote for sharing! :)

martingjohn commented 3 years ago

On your last question - I switched over to using one of these https://linitx.com/product/mikrotik-routerboard-map-lite-wireless-access-point---rbmapl-2nd/14639 which I've set up to nat between the Outlander wifi and my normal lan. If you're interested in doing that I can share all the commands I used. And then I just set up a static route on my Hassio device to route through that gateway, I had quite a struggle with using the inbuilt wifi on my raspberry pi (both setup and stability), although getting the Mikrotik thing set up wasn't overly easy but has been very stable since.

I'm very intrested on that Mikrotik setup, one vote for sharing! :)

Sure, please bear in mind that I'm very new to Mikrotik config, so go easy on any mistakes, unnecessary steps, etc. (but it does work for me) - a chunk of this was taken from https://github.com/vzakharchenko/remote-ctrl-gsm/blob/master/mikrotik/scripts/cloud/mikrotik.rsc (especially the clever restart script at the end)

So first I cleared down the settings (these might not all be necessary)

/system reset-configuration
/ip dhcp-client remove 0
/interface bridge remove 0

Set the wireless MAC address (this needs to match what your phone used to do the original peering via the app)

/interface wireless set wlan1 mac-address=xx:xx:xx:xx:xx:xx

Create security profile to connect to the Outlander (not sure if we need both wpa and wpa2) - obviously need your password

/interface wireless security-profiles
add authentication-types=wpa-psk,wpa2-psk \
    management-protection=allowed \
    mode=dynamic-keys name=Outlander \
    supplicant-identity=MikroTik \
    wpa-pre-shared-key=XXXXXXX \
    wpa2-pre-shared-key=XXXXXXX 

Connect to the Outlander - obviously need your SSID

/interface wireless
set [ find default-name=wlan1 ] \
    band=2ghz-b/g/n \
    disabled=no \
    frequency=2422 \
    installation=indoor \
    security-profile=Outlander \
    mode=station \
    ssid=XXXXX

In my setup - I've got home assistant on a vlan (if you're not, skip and use ether1 in the later steps instead of ha)

/interface vlan
add interface=ether1 name=ha vlan-id=10

Set dhcp and get ips

/ip dhcp-client 
add dhcp-options=hostname,clientid \
    disabled=no \
    add-default-route=no \
    use-peer-dns=no \
        use-peer-ntp=no \
    interface=wlan1
add dhcp-options=hostname,clientid \
    disabled=no \
    add-default-route=no \
    interface=ha

Restarted interface

/interface wireless disable wlan1
/interface wireless enable wlan1  

You should now (from the Mikrotik device) ping the Outlander /ping 192.168.8.46 NAT between the two

/ip firewall nat 
add chain=srcnat action=masquerade out-interface=wlan1
add chain=srcnat action=masquerade out-interface=ha
add action=accept chain=srcnat src-address=192.168.8.0/24
add action=accept chain=srcnat dst-address=192.168.8.0/24

You can also schedule a script to restart the interface if it drops out

/system script
add dont-require-permissions=no name=carConnectionCheck owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \n:local HOST \"192.168.8.46\"\
    \n:local PINGCOUNT 3\
    \n:local INT \"wlan1\" \
    \n:if ([/ping address=\$HOST interface=\$INT count=\$PINGCOUNT]=0) do={\
    \n:global name=\"tunnel_car\" 0\
    \n/log error \"\$INT is down\"\
    \n\
    \n/interface wireless disable wlan1\
    \n# /log error \"MitsubihiWiFI DISABLED\"\
    \n/delay delay-time=6\
    \n/interface wireless enable wlan1\
    \n# /log error \"MitsubihiWiFI ENABLED\"\
    \n# /delay delay-time=15\
    \n} else={\
    \n:global name=\"tunnel_car\" 1\
    \n}\
    \n"

/system script run carConnectionCheck

/system scheduler
add interval=3m name=carConnectionSchedule on-event=\
    "/system script run carConnectionCheck" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=sep/14/2020 start-time=10:37:49

Then on Home Assistant I added a route to the Outlander through the Mikrotik device (XXX.XXX.XXX.XXX being the IP address on ha or ether1) above, which I keep "static" using my dhcp server route add -net 192.168.8.0 netmask 255.255.255.0 gw XXX.XXX.XXX.XXX eth0 Then obviously check you can ping the Outlander from Home Assistant. I still need to add that static route in somewhere so it persists across reboots. I did try adding the route in from my normal gateway, so that Home Assistant would connect to that and then be routed to the Mikrotik and then out to the Outlander but that only seemed to work intermittently (not sure why) and given it worked directly I never dung into that further.

Hope that helps.

quenthal commented 3 years ago

On your last question - I switched over to using one of these https://linitx.com/product/mikrotik-routerboard-map-lite-wireless-access-point---rbmapl-2nd/14639 which I've set up to nat between the Outlander wifi and my normal lan. If you're interested in doing that I can share all the commands I used. And then I just set up a static route on my Hassio device to route through that gateway, I had quite a struggle with using the inbuilt wifi on my raspberry pi (both setup and stability), although getting the Mikrotik thing set up wasn't overly easy but has been very stable since.

I'm very intrested on that Mikrotik setup, one vote for sharing! :)

Sure, please bear in mind that I'm very new to Mikrotik config, so go easy on any mistakes, unnecessary steps, etc. (but it does work for me) - a chunk of this was taken from https://github.com/vzakharchenko/remote-ctrl-gsm/blob/master/mikrotik/scripts/cloud/mikrotik.rsc (especially the clever restart script at the end)

So first I cleared down the settings (these might not all be necessary)

/system reset-configuration
/ip dhcp-client remove 0
/interface bridge remove 0

Set the wireless MAC address (this needs to match what your phone used to do the original peering via the app)

/interface wireless set wlan1 mac-address=xx:xx:xx:xx:xx:xx

Create security profile to connect to the Outlander (not sure if we need both wpa and wpa2) - obviously need your password

/interface wireless security-profiles
add authentication-types=wpa-psk,wpa2-psk \
  management-protection=allowed \
  mode=dynamic-keys name=Outlander \
  supplicant-identity=MikroTik \
  wpa-pre-shared-key=XXXXXXX \
  wpa2-pre-shared-key=XXXXXXX 

Connect to the Outlander - obviously need your SSID

/interface wireless
set [ find default-name=wlan1 ] \
  band=2ghz-b/g/n \
  disabled=no \
  frequency=2422 \
  installation=indoor \
  security-profile=Outlander \
  mode=station \
  ssid=XXXXX

In my setup - I've got home assistant on a vlan (if you're not, skip and use ether1 in the later steps instead of ha)

/interface vlan
add interface=ether1 name=ha vlan-id=10

Set dhcp and get ips

/ip dhcp-client 
add dhcp-options=hostname,clientid \
  disabled=no \
  add-default-route=no \
  use-peer-dns=no \
      use-peer-ntp=no \
  interface=wlan1
add dhcp-options=hostname,clientid \
  disabled=no \
  add-default-route=no \
  interface=ha

Restarted interface

/interface wireless disable wlan1
/interface wireless enable wlan1  

You should now (from the Mikrotik device) ping the Outlander /ping 192.168.8.46 NAT between the two

/ip firewall nat 
add chain=srcnat action=masquerade out-interface=wlan1
add chain=srcnat action=masquerade out-interface=ha
add action=accept chain=srcnat src-address=192.168.8.0/24
add action=accept chain=srcnat dst-address=192.168.8.0/24

You can also schedule a script to restart the interface if it drops out

/system script
add dont-require-permissions=no name=carConnectionCheck owner=admin policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon source="\
    \n:local HOST \"192.168.8.46\"\
    \n:local PINGCOUNT 3\
    \n:local INT \"wlan1\" \
    \n:if ([/ping address=\$HOST interface=\$INT count=\$PINGCOUNT]=0) do={\
    \n:global name=\"tunnel_car\" 0\
    \n/log error \"\$INT is down\"\
    \n\
    \n/interface wireless disable wlan1\
    \n# /log error \"MitsubihiWiFI DISABLED\"\
    \n/delay delay-time=6\
    \n/interface wireless enable wlan1\
    \n# /log error \"MitsubihiWiFI ENABLED\"\
    \n# /delay delay-time=15\
    \n} else={\
    \n:global name=\"tunnel_car\" 1\
    \n}\
    \n"

/system script run carConnectionCheck

/system scheduler
add interval=3m name=carConnectionSchedule on-event=\
    "/system script run carConnectionCheck" policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon \
    start-date=sep/14/2020 start-time=10:37:49

Then on Home Assistant I added a route to the Outlander through the Mikrotik device (XXX.XXX.XXX.XXX being the IP address on ha or ether1) above, which I keep "static" using my dhcp server route add -net 192.168.8.0 netmask 255.255.255.0 gw XXX.XXX.XXX.XXX eth0 Then obviously check you can ping the Outlander from Home Assistant. I still need to add that static route in somewhere so it persists across reboots. I did try adding the route in from my normal gateway, so that Home Assistant would connect to that and then be routed to the Mikrotik and then out to the Outlander but that only seemed to work intermittently (not sure why) and given it worked directly I never dung into that further.

Hope that helps.

Thanks!

buxtronix commented 1 year ago

The 3rd point in the initial comment is addressed in a recent change, autodiscovery sets up a separate device in HA.

stefanh12 commented 1 year ago

I'm using sort of this setup, but with unraid running the docker container instead of home assistant add-on. Using the mikrotik mqtt package its actually possible to relay the information that the link has been reset, thus its then possible to trigger an automation that sends the mqtt command to phev2mqtt for wifi reset. I've removed the wifi reset code from phev2mqtt since unraid does not have the wifi connection to phev.