Hi, I have a DIY large solar sun tracker that i need some help with.
All the hardware is up and running. I am moving the software from “Blynk Local Server” to Home assistant and Esphome.
Hardware: Two linear actuators controlled by 4 relays.
Controller: ESP32 and sensor MPU6050
Current manual control code.
esphome:
name: solar_tracker
platform: ESP32
board: esp-wrover-kit
wifi:
ssid: "##########"
password: "###########"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Solar Tracker Fallback Hotspot"
password: "lZEGI44isCwX"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
i2c:
sda: 21
scl: 22
scan: True
sensor:
- platform: mpu6050
address: 0x68
update_interval: 100ms
accel_x:
name: "MPU6050 Accel X"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- -10.0 -> 270.0
- 10.0 -> 90.0
accel_y:
name: "MPU6050 Accel Y"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
- calibrate_linear:
# Map 0.0 (from sensor) to 0.0 (true value)
- 0.0 -> 90.0
- -10.0 -> 0.0
accel_z:
name: "MPU6050 Accel z"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
gyro_x:
name: "MPU6050 Gyro X"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
gyro_y:
name: "MPU6050 Gyro Y"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
gyro_z:
name: "MPU6050 Gyro z"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
temperature:
name: "MPU6050 Temperature"
filters:
- sliding_window_moving_average:
window_size: 10
send_every: 5
#relay bank Manual Switching
switch:
- platform: gpio
pin: 23
id: relayUp
name: "Solar Up"
inverted: yes
- platform: gpio
pin: 19
id: relayDown
name: "Solar Down"
inverted: yes
- platform: gpio
pin: 5
id: relayEast
name: "Solar East"
inverted: yes
- platform: gpio
pin: 17
id: relayWest
name: "Solar West"
inverted: yes
I need help!
I need to compare sun azimuth and sun elevation (from Home Assistant) with my MPU6050 data X and Y
I think the following code will expose the azimuth and elevation, but im new to coding in YAML and cant figure out how it implement this.
- platform: template
sensors:
sun_elevation:
friendly_name: "Sun Elevation"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'elevation') }}"
- platform: template
sensors:
sun_azimuth:
friendly_name: "Sun Azimuth"
unit_of_measurement: 'degrees'
value_template: "{{ state_attr('sun.sun', 'azimuth') }}"
The automation needs to be on the ESP32 as we do get power cuts and the WIFI goes off.
I really would appreciate any help as I love the esphome and home assistant platforms.
Many thanks