Closed CayCanSafety closed 2 weeks ago
Update: I was able get it to run without errors, other than www/power_data.json not existing. I added that file and now it appears to work and has data in that json. I just can't seem to get Home Assistant to see that .json now.
Hey @CayCanSafety - which model do you have? - it sounds like it may be newer than the model I'm using.
Hey @jeeshofone . It's an ECU-3 Version 4. I ended up getting everything to work, except there are 19 panels in the setup and this script only configures 12. I suspect because for some reason some inverters have an A and a B which doesn't work to pull data from?
Ok, interesting - can you send me what the script outputs for config_part.yaml
?
Sure thing:
rest:
- resource: http://homeassistant.local:8123/local/power_data.json
sensor:
- name: "Solar Panel 01 power"
value_template: '{{ value_json["303000003472 "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 01 grid frequency"
value_template: '{{ value_json["303000003472 "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 01 grid voltage"
value_template: '{{ value_json["303000003472 "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 01 temperature"
value_template: '{{ value_json["303000003472 "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 02 power"
value_template: '{{ value_json["303000003040 "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 02 grid frequency"
value_template: '{{ value_json["303000003040 "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 02 grid voltage"
value_template: '{{ value_json["303000003040 "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 02 temperature"
value_template: '{{ value_json["303000003040 "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 03 power"
value_template: '{{ value_json["303000003608 "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 03 grid frequency"
value_template: '{{ value_json["303000003608 "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 03 grid voltage"
value_template: '{{ value_json["303000003608 "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 03 temperature"
value_template: '{{ value_json["303000003608 "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 04 power"
value_template: '{{ value_json["303000004756 "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 04 grid frequency"
value_template: '{{ value_json["303000004756 "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 04 grid voltage"
value_template: '{{ value_json["303000004756 "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 04 temperature"
value_template: '{{ value_json["303000004756 "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 05 power"
value_template: '{{ value_json["403000317459-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 05 grid frequency"
value_template: '{{ value_json["403000317459-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 05 grid voltage"
value_template: '{{ value_json["403000317459-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 05 temperature"
value_template: '{{ value_json["403000317459-A "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 06 power"
value_template: '{{ value_json["403000318514-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 06 grid frequency"
value_template: '{{ value_json["403000318514-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 06 grid voltage"
value_template: '{{ value_json["403000318514-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 06 temperature"
value_template: '{{ value_json["403000318514-A "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 07 power"
value_template: '{{ value_json["303000004191 "][0] }}'
device_class: power
unit_of_measurement: "W"
- name: "Solar Panel 07 grid frequency"
value_template: '{{ value_json["303000004191 "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 07 grid voltage"
value_template: '{{ value_json["303000004191 "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 07 temperature"
value_template: '{{ value_json["303000004191 "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 08 power"
value_template: '{{ value_json["403000317903-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 08 grid frequency"
value_template: '{{ value_json["403000317903-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 08 grid voltage"
value_template: '{{ value_json["403000317903-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 08 temperature"
value_template: '{{ value_json["403000317903-A "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 09 power"
value_template: '{{ value_json["403000318319-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 09 grid frequency"
value_template: '{{ value_json["403000318319-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 09 grid voltage"
value_template: '{{ value_json["403000318319-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 09 temperature"
value_template: '{{ value_json["403000318319-A "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 10 power"
value_template: '{{ value_json["403000318934-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 10 grid frequency"
value_template: '{{ value_json["403000318934-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 10 grid voltage"
value_template: '{{ value_json["403000318934-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 10 temperature"
value_template: '{{ value_json["403000318934-A "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 11 power"
value_template: '{{ value_json["403000318699-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 11 grid frequency"
value_template: '{{ value_json["403000318699-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 11 grid voltage"
value_template: '{{ value_json["403000318699-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 11 temperature"
value_template: '{{ value_json["403000318699-A "][3] }}'
unit_of_measurement: "°C"
device_class: temperature
- name: "Solar Panel 12 power"
value_template: '{{ value_json["403000318338-A "][0] }}'
unit_of_measurement: "W"
device_class: power
- name: "Solar Panel 12 grid frequency"
value_template: '{{ value_json["403000318338-A "][1] }}'
unit_of_measurement: "Hz"
- name: "Solar Panel 12 grid voltage"
value_template: '{{ value_json["403000318338-A "][2] }}'
unit_of_measurement: "V"
- name: "Solar Panel 12 temperature"
value_template: '{{ value_json["403000318338-A "][3] }}'
unit_of_measurement: "°C"
device_class: power
I was just about to go down this path! I’m interested if you came up with anything. I tried the script and got the same error since I have a ECU-3 V4. The url is the same as @CayCanSafety, however all my inverters on that page show a A and B.
Here is a screenshot of the url @CayCanSafety switched it to. It could have something to do with the table being broken up for inverter IDs and watts but the rest is one cell for 2 values.
@SnowB0und14 - ahhh yes, that is likely what is happening.
If you can give me the raw html of the page, I think I can create a fix - the version I have populates the shared values for A and B side inverters on both lines.
@jeeshofone I had to upload it as a text file. I removed my IP and serial numbers but other than that, didn't change anything.
Thank you for looking into it!
Did that text file have what you needed? I can save it as a pdf if that helps.
Hey sorry, I haven't had a chance to look at it just yet. Working on it today!
ok, @CayCanSafety and @SnowB0und14 - could you test the branch https://github.com/jeeshofone/ha-apc-ecu-3/tree/add-ecu3-v4-support to see if that works for you?
I'm having a little trouble getting it to work. It's probably because I'm new to HA. I got the .yaml generated successfully on my local machine. I'm having trouble with the automation running. Here's the error I got from the logs: `Logger: homeassistant.components.shell_command Source: /usr/src/homeassistant/homeassistant/components/shell_command/init.py:129 integration: Shell Command (documentation, issues) First occurred: 10:27:49 AM (3 occurrences) Last logged: 10:33:58 AM
Error running command: python /config/solarhtml2json.py
, return code: 1
NoneType: None
`
It dawned on me, do I need to install beautiful soup or python in home assistant?
Thanks again for helping with this.
Actually I THINK I might know what's going on. The python script generates the config file, but it looks like it's skipping the "B" solar panel for power. Maybe the script isn't running because when it goes to scrape the table, it's got A and B? See the screenshot.
Hi @CayCanSafety, @SnowB0und14
I've made updates to support the ECU-3 and ECU-4 devices, including addressing the issues with panels having both A and B configurations. The improvements also include cleaning up temperature values correctly and ensuring each panel is assigned a unique ID in the generated configuration.
Instructions for Testing
First, make sure to clone the add-ecu3-v4-support branch of the repository:
git clone -b add-ecu3-v4-support https://github.com/jeeshofone/ha-apc-ecu-3.git
Set up a virtual environment and install the required dependencies:
cd ha-apc-ecu-3
python3 -m venv venv
source venv/bin/activate # Use .\venv\Scripts\activate
on Windows
pip install -r requirements.txt
You can fetch the power data either from a local HTML file (for testing) or a URL:
From a Local HTML File: python solarhtml2json.py --file path/to/your/file.html --ecu_v4 # For ECU v4 python solarhtml2json.py --file path/to/your/file.html # For older versions (ECU-3) From a URL: python solarhtml2json.py --url http://IP-OF-YOUR-DEVICE/index.php/realtimedata --ecu_v4 # For ECU-3 v4 python solarhtml2json.py --url http://IP-OF-YOUR-DEVICE/cgi-bin/parameters # For older versions (ECU-3 v3)
After fetching the power data, generate the Home Assistant configuration part file:
python solarhtml2json.py --generate_config
Add the contents of the generated config_part.yaml file to your configuration.yaml file in Home Assistant.
Add a shell command in Home Assistant to automate data fetching:
shell_command:
convert_solar_data: python /config/solarhtml2json.py --url http://IP-OF-YOUR-DEVICE/index.php/realtimedata --ecu_v4
convert_solar_data: python /config/solarhtml2json.py --url http://IP-OF-YOUR-DEVICE/cgi-bin/parameters Create an automation to run the fetch command at your preferred frequency:
automation:
I tired to figure this out, but I got lost in the venv part. I couldn't get it to spit out a config file to copy into HA.
(venv) ubuntu@ubuntu:~$ python '/media/share/aps/solarhtml2json.py' --generate_config Traceback (most recent call last): File "/media/share/aps/solarhtml2json.py", line 159, in <module> main() File "/media/share/aps/solarhtml2json.py", line 150, in main generate_yaml_from_json() File "/media/share/aps/solarhtml2json.py", line 86, in generate_yaml_from_json with open('www/power_data.json', 'r') as f: FileNotFoundError: [Errno 2] No such file or directory: 'www/power_data.json'
the script expects to be ran in the same directory as the project is cloned into. It looks like in this case you are in your /home/ubuntu
folder, but the script is looking for the www/power_data.json
file in the home directory - but the script and rest of the project are in /media/share/aps/
try running python solarhtml2json.py --generate_config
from inside the /media/share/aps/
folder
I got it to run, thanks for the help! I didn't realize it needed the www folder. I'll try it and get back to you.
Ok I got the config file created. I just can't seem to get HA to update the sensor data. Do I have to install the Python dependencies in HA as well? I didn't see anything in the logs, and I tried changing it to python3 instead of python, and that triggered an error, so I assume it's just not populating for some reason.
@SnowB0und14 - a couple troubleshooting steps
shell_command
updated to the latest version using convert_solar_data: python /config/solarhtml2json.py --url http://ip-of-your-device/index.php/realtimedata --ecu_v4
(mine is v3 and looks like this:is your automation set up to call the shell script?
if you're enabling it for the first time at night, then you might be falling into a know issue #4 - the current fix for that is to restart ha during the day after each panel is reporting information back. (I've got an idea for a fix here, but not done yet)
I would expect some logs to exist if the automation is calling the script and it is failing. HA comes with requests, BeautifulSoup datetime and json packages already installed. So you shouldn't need to add these again.
@jeeshofone
Thanks for the help! I got it working! The www folder and power_data.json got me again. I didn't realize I needed to add that to HA as well. I thought that was just for setup. Those screenshots were a HUGE help!
Awesome! I'll merge the branch into main! Also thank you for testing this with me - I'll make sure to update the docs with more images and troubleshooting steps as well to help future people out.
marking this as solved - @CayCanSafety - can you confirm if this also works for you? Feel free to re-open if not
Hello,
When I tried to run 'populate-configuration.py' I kept getting a 404 error. After some playing around, I changed the address from the cgi-bin to "http://10.0.0.166/index.php/realtimedata". This worked with the result: "Found 12 inverters". I copied over the JSON data and setup the shell command. I can't get things to work yet though.
If I manually run 'solarhtml2json.py' in my terminal I get this:
Not a power data row Not a power data row Not a power data row Not a power data row Not a power data row Not a power data row Not a power data row Not a power data row Traceback (most recent call last): File "/dockerapps/homeassistant/config/solarhtml2json.py", line 60, in <module> get_power_data() File "/dockerapps/homeassistant/config/solarhtml2json.py", line 57, in get_power_data with open('www/power_data.json', 'w') as outfile: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'www/power_data.json'
In Home Assistant, I'm just showing that the Shell Command ran, but nothing updates or happens.