Closed omriasta closed 2 years ago
I'll see what I can hammer out.
Great, if you create a branch and get me the general direction I can try to test and fill in anything missing.
Would you be able to provide a dump of the mqtt topic? OpenEVSE 4.1.0 doesn't connect to my MQTT broker for some unknown reason or I'd grab a dump myself.
Will do as soon as I get home
Here you go:
Listen to a topic
Topic to subscribe to
openevse/#
Message 16 received on openevse/srssi at 8:14 AM:
-70
QoS: 0 - Retain: false
Message 15 received on openevse/divertmode at 8:14 AM:
1
QoS: 0 - Retain: false
Message 14 received on openevse/freeram at 8:14 AM:
209640
QoS: 0 - Retain: false
Message 13 received on openevse/manual_override at 8:14 AM:
0
QoS: 0 - Retain: false
Message 12 received on openevse/colour at 8:14 AM:
5
QoS: 0 - Retain: false
Message 11 received on openevse/vehicle at 8:14 AM:
0
QoS: 0 - Retain: false
Message 10 received on openevse/state at 8:14 AM:
254
QoS: 0 - Retain: false
Message 9 received on openevse/temp4 at 8:14 AM:
240
QoS: 0 - Retain: false
Message 8 received on openevse/temp3 at 8:14 AM:
false
QoS: 0 - Retain: false
Message 7 received on openevse/temp2 at 8:14 AM:
false
QoS: 0 - Retain: false
Message 6 received on openevse/temp1 at 8:14 AM:
145
QoS: 0 - Retain: false
Message 5 received on openevse/temp at 8:14 AM:
145
QoS: 0 - Retain: false
Message 4 received on openevse/wh at 8:14 AM:
455778
QoS: 0 - Retain: false
Message 3 received on openevse/pilot at 8:14 AM:
40
QoS: 0 - Retain: false
Message 2 received on openevse/voltage at 8:14 AM:
240
QoS: 0 - Retain: false
Message 1 received on openevse/amp at 8:14 AM:
0
QoS: 0 - Retain: false
Message 0 received on openevse/announce/e154 at 8:14 AM:
{
"state": "connected",
"id": "9c9xxxxxxx54",
"name": "openevse-e154",
"mqtt": "openevse",
"http": "http://192.168.XX.XX/"
}
QoS: 0 - Retain: true
Thanks, I'll see what I can do
Do you think just enabling auto discovery would be enough?
I think the best way would be to create a property for each device which will define if it is mqtt or http, then we would have to create all the entities based on that property ie if charger.connection = http then use existing way to create entities, if charger.connection = mqtt then create entities using the mqtt connection..... Also, the config flow should have an initial step which should ask if you are adding http or mqtt and then provide appropriate fields (mqtt would have to provide a topic and no authentication rather than an ip/host).
I think the easiest way would be to have openevse publish the discovery topics via the firmware honestly, that way the integration doesn't have to reinvent the wheel.
Not sure I understand how that would work? Currently I have yaml entries for every entity with the mqtt platform set. If the integration autodiscovered the mqtt topic how would it know how to setup the switch, sensors etc.?
Auto discovery sets up the switch/sensors/etc based on the topics here's an example:
topic: openevse/pilot
value: 40
Discovery topic: homeassistant/sensor/openevse/pilot/config
value: {"name": "openevse pilot", "unit_of_measure": "A", "icon": "mdi:sine-wave", "state_topic": "openevse/pilot", "unique_id": "9c9xxxxxxx54_pilot" }
The discovery topic tells Home Assistant to look at openevse/pilot
for the sensor
data and generate the entity based on the other data contained in homeassistant/sensor/openevse/pilot/config
awesome, was not aware how that worked. I guess that would be the way to go then...would it be able to discover if the base topic is not openevse? In my instance I have 2 units and each has it's own topic...Sorry just not that familiar with how the discovery works.....
The topics can be anything, the state topic is where you'd point everything to, ideally the device would generate all this. I'll see if maybe I can piece together a PR for OpenEVSE to enable HomeAssistant auto discovery, honestly shouldn't be too difficult since it's just publishing extra topics.
Or submit a feature request, I'm terrible with UI stuff lol
That would be great, just hope that they update the 2.9.x version as well and not just the 4.x version. The 2.9.x mqtt looks like this and doesn't have the initial announcement that the 4.x has on openevse/announce (as you can see above) :
Listen to a topic
Topic to subscribe to
openevse_work/#
Message 12 received on openevse_work/srssi at 10:42 AM:
-70
QoS: 0 - Retain: false
Message 11 received on openevse_work/divertmode at 10:42 AM:
1
QoS: 0 - Retain: false
Message 10 received on openevse_work/freeram at 10:42 AM:
15312
QoS: 0 - Retain: false
Message 9 received on openevse_work/state at 10:42 AM:
254
QoS: 0 - Retain: false
Message 8 received on openevse_work/temp3 at 10:42 AM:
false
QoS: 0 - Retain: false
Message 7 received on openevse_work/temp2 at 10:42 AM:
false
QoS: 0 - Retain: false
Message 6 received on openevse_work/temp1 at 10:42 AM:
205
QoS: 0 - Retain: false
Message 5 received on openevse_work/wh at 10:42 AM:
346953
QoS: 0 - Retain: false
Message 4 received on openevse_work/pilot at 10:42 AM:
40
QoS: 0 - Retain: false
Message 3 received on openevse_work/voltage at 10:42 AM:
240
QoS: 0 - Retain: false
Message 2 received on openevse_work/amp at 10:42 AM:
0
QoS: 0 - Retain: false
Message 1 received on openevse_work/emoncms_message at 10:42 AM:
null
QoS: 0 - Retain: false
Message 0 received on openevse_work/emoncms_connected at 10:42 AM:
1
QoS: 0 - Retain: false
I guess the change could be made here and possibly also copied to 2.9.x and then recompiled: https://github.com/OpenEVSE/ESP32_WiFi_V4.x/blob/80f66b4026e40bf0773aa7267c11d4e7044a9355/src/mqtt.cpp#L188
I assume the mqtt discovery you are mentioning is this: https://www.home-assistant.io/docs/mqtt/discovery/
Yes that's the discovery info.
I have been messing around with it a bit by manually creating entities by publishing to mqtt....sensors are easy but I can't figure out the switch... I assume I need a value_template for the state {{ "off" if value == 254 else "on"}} but every variation I have tried so far and looking through the forums, I just couldn't get it to work....
that one's a little trickier, I'll see if I can get you a good topic for it, I assume for divertmode and/or manual_override right?
I usually use the $FS and $FE RAPI commands for the action so the switch state should be off when OpenEVSE reports the state 254 or 255 and otherwise it should be on. I have mine slightly different where the switch is called OpenEVSE enable/disable as opposed to your integration which is on to activate sleep and off to start charging.
Which wifi firmware are you running?
wifi firmware is 4.1.0 and openevse firmware is 7.1.3 BUT the openevse hardware itself is actually v4 not the latest v5.5
How do you currently have the switch setup for MQTT control, or do you not at this time?
Using @TonyApuzzo package found here https://github.com/TonyApuzzo/home-assistant-config/blob/master/packages/openevse2.yaml
- trigger:
- platform: mqtt
topic: openevse/state
sensor:
- name: OpenEVSE State
state: >-
{%- set value = trigger.payload -%}
{%- if value | regex_match('^[01]$') -%}
Not Connected
{%- elif value | regex_match('^2$') -%}
Connected
{%- elif value | regex_match('^3$') -%}
Charging
{%- elif value | regex_match('^([456789]|10)$') -%}
Error ({{- value -}})
{%- elif value | regex_match('^254$') -%}
Sleeping
{%- elif value | regex_match('^255$') -%}
Disabled
{%- else -%}
Unknown ({{- value -}})
{%- endif -%}
icon: >-
{%- set value = trigger.payload -%}
{%- if value | regex_match('^[01]$') -%}
mdi:power-plug-off
{%- elif value | regex_match('^2$') -%}
mdi:car
{%- elif value | regex_match('^3$') -%}
mdi:car-electric
{%- elif value | regex_match('^([456789]|10)$') -%}
mdi:battery-alert
{%- elif value | regex_match('^254$') -%}
mdi:sleep
{%- elif value | regex_match('^255$') -%}
mdi:power-off
{%- else -%}
mdi:battery-unknown
{%- endif -%}
attributes:
topic: '{{- trigger.topic -}}'
payload: '{{- trigger.payload -}}'
switch:
- platform: template
switches:
openevse_enablement:
friendly_name: OpenEVSE Disable/Enable
icon_template: mdi:ev-station
value_template: >-
{{-
not state_attr('sensor.openevse_state', 'payload') in (254, 255)
-}}
turn_on:
service: script.openevse_rapi_fe
turn_off:
service: script.openevse_rapi_fd
ah it uses a script, I think that's the only way to really get the switch part working due to the way the topics are setup
Looking at the info, I think it's doable for the action though haven't even tried that yet (using payload_on and payload_off settings) Just couldn't figure the value_template option to get state of switch, according to the documentation it should be doable just couldn't figure the proper syntax to get it to work
I think I see what you mean now.... I temporarily setup the switch with the below code. Now the switch was following the actual state (given only those 2 options for state obviously). I then tried to work on the actual commands but homeassistant expects one topic with different payloads and openevse expects 2 different topics with no payload. I guess the only way to make this easier to setup would be to completely overhaul the mqtt implementation in OpenEVSE which doesn't seem likely to me...
I guess I'll stick with your integration for the local and the yaml package for the remote device for now but I guess they should look into changing up the mqtt implementation in openevse....it just doesn't make that much sense to me the way it is currently functioning....
service: mqtt.publish
data:
topic: homeassistant/switch/openevse/config
payload: >-
{"name": "openevse-test", "command_topic": "openevse/rapi/in/",
"state_topic": "openevse/state", "state_off": "254", "state_on": "1"}
It would be great to add the option to use mqtt as well to the config flow.... I hope this is the place for feature requests... I'll try to give it a go on my end though my python is pretty basic