I have got my solar charger working with an ESP8266 receiving a value from an HA automation which it uses to set the output of a MCP4725 DAC.
What I don’t understand is how to monitor that DAC value in home assistant? I am reading through the section on lambdas and publish_state() and getting nowhere.
Any help on being able to see what the DAC is set to would be greatly appreciated.
The code from the device in ESPhome is:
esphome:
name: evsecontroller
friendly_name: EVSEcontroller
on_boot:
- priority: 600
then:
- lambda: |-
id(output_voltage).set_level(0);
esp8266:
board: esp01_1m
# Enable logging
logger:
# Set a global i2c connection
i2c:
sda: GPIO4
scl: GPIO5
scan: true
# Set the output with default (address: 0x60 / global i2c)
output:
- platform: mcp4725
id: output_voltage
# Enable Home Assistant API
api:
encryption:
key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
services:
- service: set_dac_value
variables:
dac_value: int
then:
- output.set_level:
id: output_voltage
level: !lambda 'return dac_value / 4096.0;'
ota:
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
wifi:
ssid: !secret wifi_password
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Evsecontroller Fallback Hotspot"
password: "xxxxxxxxxxxxxxxxxx"
captive_portal:
And the automation that sets the DAC value according to available export power is:
- id: Solar charging optimisation
alias: Solar charging optimisation
trigger:
- platform: state
entity_id:
- sensor.export_minus_charger_immersion
condition:
- condition: sun
after: sunrise
after_offset: '2'
- condition: sun
before: sunset
before_offset: '2'
- condition: not
conditions:
- condition: state
entity_id: device_tracker.evsedac
state: unavailable
- condition: state
entity_id: input_select.car_charge_mode
state: 'Solar'
action:
- if:
- condition: numeric_state
entity_id: sensor.export_power_moving_average
above: 1440
then:
- service: esphome.evsecontroller_set_dac_value
data_template:
dac_value: '{% set i = states(''sensor.export_minus_charger_immersion'') | int %}
{% if i > 3120 %} 1448
{% elif i > 2880 %} 1368
{% elif i > 2640 %} 1319
{% elif i > 2400 %} 1249
{% elif i > 2160 %} 1198
{% elif i > 1920 %} 1136
{% elif i > 1680 %} 1065
{% elif i > 1440 %} 1008
{% endif %}'
- if:
- condition: numeric_state
entity_id: sensor.export_power_moving_average
below: 1440
then:
- service: esphome.evsecontroller_set_dac_value
data_template:
dac_value: '0'
mode: single