Download the Raspberry PI imager here
sudo apt update
sudo apt upgrade
sudo apt install -y network-manager
sudo apt install -y golang
sudo apt install -y libpcap-dev
git clone https://github.com/Roysteroonie/phev2mqtt.git
cd phev2mqtt
go build
phev2mqtt --help
The output should look like this:-
"See below for subcommands. For further information
on this tool, see https://github.com/Roysteroonie/phev2mqtt.
Usage:
phev2mqtt [command]
Available Commands:
client Client to connect and interact with the vehicle
completion generate the autocompletion script for the specified shell
decode Commands to decode Phev messages
emulator Emulate a car, to enable app testing
help Help about any command
Flags:
--config string config file (default is $HOME/.phev2mqtt.yaml)
-h, --help help for phev2mqtt
-s, --log_syslog plain logging to syslog instead of console
-t, --log_timestamps coloured logging with timestamps
-v, --verbosity string logging level to use (default "info")
Use "phev2mqtt [command] --help" for more information about a command."
sudo nano /etc/systemd/system/phev2mqtt.service
[Unit]
Description=phev2mqtt service script
StartLimitIntervalSec=5
After=syslog.target network.target
[Service]
Type=exec
ExecStart=/usr/local/bin/phev2mqtt --config=/dev/null client mqtt --mqtt_server tcp://MQTT_SERVER_IP:1883/ --mqtt_username USERNAME --mqtt_password PASSWORD -v=debug
# Restart script if stopped
Restart=always
# Wait 30s before restart
RestartSec=30s
# Tag things in the log
# View with: sudo journalctl -f -u phev2mqtt -o cat
SyslogIdentifier=phev2mqtt
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
sudo cp phev2mqtt /usr/local/bin/
sudo chmod 755 /usr/local/bin/phev2mqtt
phev2mqtt client mqtt --mqtt_server tcp://MQTT_SERVER_IP:1883/ --mqtt_username USERNAME --mqtt_password PASSWORD
sudo nano /etc/systemd/network/00-default.link
[Match]
# This should be the 'real' (default) mac address of the Pi's wireless interface.
# To obtain this use "ip a"
MACAddress=Your local mac address
[Link]
# This should be the MAC address to use to connect to the car, per above.
MACAddress=Your mac address from your mobile wifi for the car
NamePolicy=kernel database onboard slot path
NetworkManager and use nmcli, but don't let both manage wlan0 simultaneously.sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB # Change this to suit your local
network={
ssid="YOUR CARS SSID"
scan_ssid=1
psk="WIFI PASSWORD"
}
nmcli
sudo nmcli connection add \
type wifi \
ifname wlan0 \
con-name Your Car SSID \
ssid Your Car SSID
sudo nmcli connection modify CAR WIFI SSID \
wifi-sec.key-mgmt wpa-psk \
wifi-sec.psk CAR WIFI PASSWORD \
802-11-wireless.cloned-mac-address MAC ADRESS USED ABOVE
sudo nmcli connection up Your Car SSID
3: wlan0: mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether "Your cloned mac address" brd ff:ff:ff:ff:ff:ff permaddr b8:27:eb:40:b5:64
inet 192.168.8.47/24 brd 192.168.8.255 scope global dynamic noprefixroute wlan0
valid_lft 86385sec preferred_lft 86385sec
inet6 fe80::f51c:8587:db3a:4143/64 scope link noprefixroute
sudo reboot
phev2mqtt client register --address 192.168.8.46:8080 -v=debug
level=debug msg="%PHEV_TCP_READER_CLOSE%"
level=error msg="Connection closed."
level=info msg="Success!"
sudo systemctl daemon-reload
sudo systemctl enable phev2mqtt.service
sudo systemctl start phev2mqtt.service
sudo journalctl -u phev2mqtt.service -f
Feb 02 17:02:29 phev2mqtt phev2mqtt[9863]: level=debug msg="%PHEV_TCP_SEND_MSG%: [57] PING REQ (id f)"views:
- title: Home
cards:
- type: horizontal-stack
cards:
- type: picture-elements
elements:
- type: state-icon
entity: light.phev_"YOUR CAR VIN"_phev_park_lights
style:
top: 95%
left: 30%
icon: mdi:car-parking-lights
- type: state-icon
entity: light.phev_"YOUR CAR VIN"_phev_head_lights
style:
top: 5%
left: 50%
icon: mdi:car-light-high
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_boot
style:
top: 90%
left: 50%
icon: mdi:car-connected
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_bonnet
style:
top: 17%
left: 50%
icon: mdi:car
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_front_passenger_door
icon: mdi:car-door
style:
top: 50%
left: 7%
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_driver_door
icon: mdi:car-door
style:
top: 50%
left: 90%
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_rear_left_door
icon: mdi:car-door
style:
top: 65%
left: 7%
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_rear_right_door
icon: mdi:car-door
style:
top: 65%
left: 90%
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_charger_connected
style:
top: 80%
left: 90%
- type: state-icon
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_locked
style:
top: 60%
left: 50%
image: https://ha.cactii.net/local/car-top-1.png
- type: gauge
tap_action:
action: toggle
entity: sensor.phev_"YOUR CAR VIN"_phev_battery
unit: '%'
- type: custom:button-card
entity: binary_sensor.phev_"YOUR CAR VIN"_phev_charger_connected
name: Charger
aspect_ratio: 1/1.7
tap_action:
action: more-info
entity: switch.phev_"YOUR CAR VIN"_phev_disable_charge_timer
styles:
grid:
- position: relative
custom_fields:
notification:
- background-color: |
[[[
if (states['binary_sensor.phev_"YOUR CAR VIN"_phev_charging'].state == "on")
return "green";
return "red";
]]]
- border-radius: 50%
- position: absolute
- left: 60%
- top: 10%
- height: 40px
- width: 40px
- font-size: 14px
- line-height: 40px
custom_fields:
notification: >
[[[ return
Math.floor(states['sensor.phev_"YOUR CAR VIN"_phev_charge_remaining'].state)
+'m']]]
state:
- value: 'on'
icon: mdi:power-plug
label: Plugged In
- value: 'off'
icon: mdi:power-plug-off
label: Unplugged
- type: horizontal-stack
cards:
- show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: switch.phev_"YOUR CAR VIN"_phev_cool
- show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: switch.phev_"YOUR CAR VIN"_phev_heat
- show_name: true
show_icon: true
type: button
tap_action:
action: toggle
entity: switch.phev_"YOUR CAR VIN"_phev_windscreen