I just wanted to share my “smart charger”.
It uses the Home Assistant companion app to know what device is charging on this plug and stops the charge at 90% (ish).
It is built in Node red and has a Lovelace picture elements card to display the device and the current battery level.
When you charge something that does not have the companion app installed and the flow can’t determine what is being charged then it will leave the plug on for two hours and display the countdown in Lovelace.
All you need is a smart plug and a USB charger connected to it, and the Home Assistant companion app installed on the devices you want to charge.
Even though the sequence in Node red is very large, I have used change nodes and function nodes to make sure the entities should only be declared once and then they are passed along with the messages.
That way it is not that many nodes that needs to be changed.
All nodes that needs to be changed is commented in the flow with a comment node and in some nodes there is a description.
yaml
configuration.yaml
input_boolean:
ha_two_min_after_restart: # this is to start up the sequence again if it was on when you rebooted HA
name: turns on two minutes after restart
initial: false
charger_vardagsrum_GUI: # This boolean tells Lovelace to hide/display the view
name: charger_vardagsrum_GUI
charger_vardagsrum_known: # this determins if the device has companion app installed and displays the name and battery level or time left
name: charger_vardagsrum_GUI
input_text:
charger_vardagsrum_device: # the friendly name of the device that is charged
name: charger_vardagsrum_device
icon: mdi:cellphone-charging
charger_vardagsrum_header: # what is displayed as header in the picture element card
name: charger_vardagsrum_header
icon: mdi:usb-port
initial: "Smart laddare vardagsrum"
charger_vardagsrum_percent: # battery level of the device that is charged
name: charger_vardagsrum_percent
charger_vardagsrum_time_left: # time left if the device on charge does not have home assistant app installed
name: charger_vardagsrum_time_left
icon: mdi:clock-time-eight-outline
sensor:
- platform: uptime # uptime sensor that is used to trigger the automation
unit_of_measurement: minutes
customize.yaml
customize:
input_text.charger_vardagsrum_percent:
unit_of_measurement: '%'
input_text.charger_vardagsrum_header:
templates:
# change switch to what you use
icon_color: if (entities['switch.32431260c44f33bed286'].state == 'off') return 'rgb(255,0,0)';
if (entities['switch.32431260c44f33bed286'].state == 'on') return 'rgb(0,255,0)';
automations.yaml
- id: '1597354226140'
alias: After restart set boolean to on
description: ''
trigger:
- above: '2'
entity_id: sensor.uptime
platform: numeric_state
condition:
- condition: state
entity_id: input_boolean.ha_two_min_after_restart
state: 'off'
action:
- data: {}
entity_id: input_boolean.ha_two_min_after_restart
service: input_boolean.turn_on
mode: single
Lovelace:
elements:
- entity: input_text.charger_vardagsrum_header
style:
left: 10%
top: 17%
transform: 'scale(2,2)'
tap_action:
action: call-service
service: switch.toggle
service_data:
entity_id: switch.32431260c44f33bed286
type: state-icon
- entity: input_text.charger_vardagsrum_header
style:
left: 30%
top: 17%
transform: 'scale(1.5,1.7)'
tap_action:
action: call-service
service: switch.toggle
service_data:
entity_id: switch.32431260c44f33bed286
type: state-label
- conditions:
- entity: input_boolean.charger_vardagsrum_gui
state: 'on'
elements:
- icon: 'mdi:tablet-cellphone'
style:
left: 15%
top: 43%
transform: 'scale(2,2)'
type: icon
- entity: input_text.charger_vardagsrum_device
style:
left: 30%
top: 42%
transform: 'scale(1.5,1.5)'
type: state-label
- conditions:
- entity: input_boolean.charger_vardagsrum_known
state: 'on'
elements:
- icon: 'mdi:cellphone-charging'
style:
left: 14%
top: 67%
transform: 'scale(2,2)'
type: icon
- entity: input_text.charger_vardagsrum_percent
style:
left: 27%
top: 65%
transform: 'scale(1.5,1.5)'
type: state-label
type: conditional
- conditions:
- entity: input_boolean.charger_vardagsrum_known
state: 'off'
elements:
- icon: 'mdi:clock-time-eight-outline'
style:
left: 15%
top: 67%
transform: 'scale(2,2)'
type: icon
- entity: input_text.charger_vardagsrum_time_left
style:
left: 30%
top: 65%
transform: 'scale(1.5,1.5)'
type: state-label
type: conditional
type: conditional
image: local/frame.png
style: null
tap_action:
action: none
type: picture-elements
Resources:
Frame:
http://hoppvader.nu/bilder/frame.png
Sound file:
http://hoppvader.nu/bilder/Magic_Wand_Noise.mp3
Couldn’t add the Node red here since there is a limit of characters.
It’s in this file:
http://hoppvader.nu/bilder/Node_red.txt