QCells Q.Home energy dashboard questions

Hello,
Thank you for the great explanation, it works perfectly. Unfortunately I can’t manage to use the Qcells values in an automation. For example, I would like to switch on a pool pump automatically at 8.00 a.m. when the battery is still more than 40% charged. You can select an entity, but nothing happens at 8:00 a.m. I would be very grateful for a tip.

Sorry for the delay. This is easy - use a numeric state trigger:

platform: numeric_state
entity_id: sensor.qcells_cloud_solar_plus_battery_total
above: sensor.qcells_cloud_house_load <-- This is a input number helper
for:
  hours: 0
  minutes: 5
  seconds: 0

Uah, this is way beyond my knowledge. The only time the Cloud is not available to me is when there’s an update of the cloud. That happened 2-3 times in the last six months. Why do you have so many problems with the cloud availability?

Did you ever check if there is a problem with your internet connection? Might be related to your internet service provider or router.

Very helpful explanation. Thank you.
Where do you put the template for the Strompreis? I could not find a place in the UI, which does not allow this complex structure. Is the place in ./config/.storage/energy ? And how do I activate it?
Thank you

Yes I have checked the connection and cannot find any problems. However, I have experimented a little with the timeout and the scan interval. I now let the home assistant ask for new values every 60 seconds and allow a timeout of up to 180 seconds. This is still not optimal, but since then my graphs look better.

# Q-Save 9.1 --> 8300W usable minus 10% minimum load multiplied by soc
# E.g. 35% soc --> 2614.5 W
      qcells_cloud_battery_usable:
        friendly_name: QCells Cloud Battery usable
        value_template: "{{ 8300 * 0.9 * (max(states('sensor.qcells_cloud_soc') | float(default=0) - 10, 0) / 100) }}"
        unit_of_measurement: W
        device_class: power

Is it possible that your code deducts the 10% twice?

In your example Homeassitant calculates 8300x0,9x0,9x0,35=2353,05W :frowning:

Good find. Corrected in first post.

During development I got wrong values when SOC went down to e.g. 10 % without solar productivity. I never found the reason. With these two 10 % off I ended on 10 % SOC and the correct remaining W.

Over the months I switched back and forward several times. The last and correct version is in my code. Forgot to apply it here.

Thanks.

It’s in configuration.yaml too. It should build a complete template block.

        unit_of_measurement: "kW"
        device_class: energy

I have found another minor problem. In the following lines, the device_class is “Energy” but the unit is “W”. The unit should be “Wh”, otherwise you will get error messages in the log of the home assistant that the wrong unit was selected.

Had to upgrade HomeAssistant to see this error and now I see many errors more. I will delete this thread because I don’t know what all these new errors mean. I now see Render errors on DateTime calculations and lots more. Terrible.

Just look at this out of many more. That worked in the past. It’s power, not percentage - now I do receive an error:

Entity sensor.qcells_cloud_batpower (<class ‘homeassistant.components.template.sensor.SensorTemplate’>) is using native unit of measurement ‘W’ which is not a valid unit for the device class (‘battery’) it is using; expected one of [‘%’];

This little piece of code worked for 6 months, now it’s broken.

Sorry for this inconvenience.

I have adjusted your code in a few places and it runs error-free in the latest version.

Home Assistant 2023.7.1
Supervisor 2023.07.1
Operating System 10.3
Frontend 20230705.1 - latest

# QCells Cloud
sensor:
  - platform: rest
    name: QCells Cloud
    resource: !secret qcells_cloud
    method: GET
    scan_interval: 60
    timeout: 60
    value_template: 'OK'
    json_attributes_path: "$.result"
    json_attributes:
      - sn
      - acpower
      - yieldtoday
      - yieldtotal
      - feedinpower
      - feedinenergy
      - consumeenergy
      - feedinpowerM2
      - soc
      - peps1
      - peps2
      - peps3
      - inverterType
      - inverterStatus
      - uploadTime
      - batPower
      - powerdc1
      - powerdc2
      - powerdc3
      - powerdc4
      - batStatus
  - platform: template
    sensors:
      qcells_cloud_sn:
        friendly_name: "QCells Unique identifier of communication module"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'sn') }}"
      qcells_cloud_acpower:
        friendly_name: "QCells Inverter AC power total"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'acpower') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_yieldtoday:
        friendly_name: "QCells Inverter AC energy out daily"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'yieldtoday') }}"
        unit_of_measurement: "kWh"
        device_class: energy
      qcells_cloud_yieldtotal:
        friendly_name: "QCells Inverter AC energy out total"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'yieldtotal') }}"
        unit_of_measurement: "kWh"
        device_class: energy
      qcells_cloud_feedinpower:
        friendly_name: "QCells Grid power total"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'feedinpower') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_feedinenergy:
        friendly_name: "QCells Grid energy to Grid total"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'feedinenergy') }}"
        unit_of_measurement: "kWh"
        device_class: energy
      qcells_cloud_consumeenergy:
        friendly_name: "QCells Grid energy from Grid total "
        value_template: "{{ state_attr('sensor.qcells_cloud', 'consumeenergy') }}"
        unit_of_measurement: "kWh"
        device_class: energy
      qcells_cloud_feedinpowerm2:
        friendly_name: "QCells Inverter Meter2 AC power total"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'feedinpowerM2') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_soc:
        friendly_name: "QCells BMS energy SOC"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'soc') | round(0) }}"
        unit_of_measurement: "%"
      qcells_cloud_peps1:
        friendly_name: "QCells Inverter AC EPS power 1"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'peps1') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_peps2:
        friendly_name: "QCells Inverter AC EPS power 2"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'peps2') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_peps3:
        friendly_name: "QCells Inverter AC EPS power 3"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'peps3') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_invertertype:
        friendly_name: "QCells Inverter Type"
        value_template: >-
          {% if state_attr('sensor.qcells_cloud', 'inverterType') == "1" %}
            X1-LX
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "2" %}
            X-Hybrid
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "3" %}
            X1-Hybiyd/Fit
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "4" %}
            X1-Boost/Air/Mini
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "5" %}
            X3-Hybiyd/Fit
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "6" %}
            X3-20K/30K
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "7" %}
            X3-MIC/PRO
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "8" %}
            X1-Smart
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "9" %}
            X1-AC
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "10" %}
            A1-Hybrid
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "11" %}
            A1-Fit
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "12" %}
            A1-Grid
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "13" %}
            J1-ESS
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "14" %}
            X3-Hybrid-G4
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "15" %}
            X1-Hybrid-G4
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "16" %}
            X3-MIC/PRO-G2
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "17" %}
            X1-SPT
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "18" %}
            X1-Boost/Mini-G4
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "19" %}
            A1-HYB-G2
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "20" %}
            A1-AC-G2
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "21" %}
            A1-SMT-G2
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "22" %}
            X3-FTH
          {% elif state_attr('sensor.qcells_cloud', 'inverterType') == "23" %}
            X3-MGA-G2
          {% else %}
            Unknown
          {% endif %}
      qcells_cloud_inverterstatus:
        friendly_name: "QCells Inverter status"
        value_template: >-
          {% if state_attr('sensor.qcells_cloud', 'inverterStatus') == "100" %}
            Wait Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "101" %}
            Check Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "102" %}
            Normal Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "103" %}
            Fault Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "104" %}
            Permanent Fault Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "105" %}
            Update Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "106" %}
            EPS Check Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "107" %}
            EPS Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "108" %}
            Self-Test Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "109" %}
            Idle Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "110" %}
            Standby Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "111" %}
            Pv Wake Up Bat Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "112" %}
            Gen Check Mode
          {% elif state_attr('sensor.qcells_cloud', 'inverterStatus') == "113" %}
            Gen Run Mode
          {% else %}
            Unknown status
          {% endif %}
      qcells_cloud_uploadtime:
        friendly_name: "QCells Update time"
        value_template: "{{ as_timestamp(state_attr('sensor.qcells_cloud', 'uploadTime')) | timestamp_local }}"
        device_class: timestamp
      qcells_cloud_batpower:
        friendly_name: "QCells Inverter DC Battery power total"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'batPower') }}"
        unit_of_measurement: "W"
        device_class: battery
      qcells_cloud_powerdc1 :
        friendly_name: "QCells Inverter DC PV power MPPT1"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'powerdc1') }}"
        device_class: power
        unit_of_measurement: "W"
      qcells_cloud_powerdc2:
        friendly_name: "QCells Inverter DC PV power MPPT2"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'powerdc2') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_powerdc3:
        friendly_name: "QCells Inverter DC PV power MPPT3"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'powerdc3') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_powerdc4:
        friendly_name: "QCells Inverter DC PV power MPPT4"
        value_template: "{{ state_attr('sensor.qcells_cloud', 'powerdc4') }}"
        unit_of_measurement: "W"
        device_class: power
      qcells_cloud_batstatus:
        friendly_name: "QCells BMS Status"
        value_template: >-
          {% if state_attr('sensor.qcells_cloud', 'batStatus') == "0" %}
            Self Use Mode
          {% elif state_attr('sensor.qcells_cloud', 'batStatus') == "1" %}
            Force Time Use
          {% elif state_attr('sensor.qcells_cloud', 'batStatus') == "2" %}
            Back Up Mode
          {% elif state_attr('sensor.qcells_cloud', 'batStatus') == "3" %}
            Feed-in Priority
          {% else %}
            Unknown status
          {% endif %}
# Adding all possible solar strings to one value
      qcells_cloud_powerdc_sum:
        friendly_name: "QCells Inverter DC PV power sum"
        value_template: "{{ states('sensor.qcells_cloud_powerdc1') | float(default=0) + states('sensor.qcells_cloud_powerdc2') | float(default=0) + states('sensor.qcells_cloud_powerdc3') | float(default=0) + states('sensor.qcells_cloud_powerdc4') | float(default=0) }}"
        unit_of_measurement: "W"
        device_class: power
# Calculate house load because this is not part of the Cloud result
      qcells_cloud_house_load:
        friendly_name: QCells Cloud House Load
        value_template: "{{ states('sensor.qcells_cloud_feedinpowerm2') | float(default=0) + states('sensor.qcells_cloud_acpower') | float(default=0) - states('sensor.qcells_cloud_feedinpower') | float(default=0) }}"
        unit_of_measurement: W
        device_class: power
# Battery is being charged
      qcells_cloud_battery_charge:
        friendly_name: QCells Cloud Battery Charge
        value_template: >
          {% if states('sensor.qcells_cloud_batpower') | float(default=0) > 0 %}
            {{ states('sensor.qcells_cloud_batpower') | float(default=0) }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: W
        device_class: power
# Battery is being discharged
      qcells_cloud_battery_discharge:
        friendly_name: QCells Cloud Battery Discharge
        value_template: >
          {% if states('sensor.qcells_cloud_batpower') | float(default=0) < 0 %}
            {{ states('sensor.qcells_cloud_batpower') | float(default=0) | abs }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: W
        device_class: power
# Feed to grid
      qcells_cloud_grid_feed:
        friendly_name: QCells Cloud Grid Feed
        value_template: >
          {% if states('sensor.qcells_cloud_feedinpower') | float(default=0) > 0 %}
            {{ states('sensor.qcells_cloud_feedinpower') | float(default=0) }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: W
        device_class: power
# Load from grid
      qcells_cloud_grid_load:
        friendly_name: QCells Cloud Grid Load
        value_template: >
          {% if states('sensor.qcells_cloud_feedinpower') | float(default=0) < 0 %}
            {{ states('sensor.qcells_cloud_feedinpower') | float(default=0) | abs }}
          {% else %}
            0
          {% endif %}
        unit_of_measurement: W
        device_class: power
# Q-Save 9.1 --> 8300W usable minus 10% minimum load multiplied by soc E.g. 35% soc --> 2614.5 W
      qcells_cloud_battery_usable:
        friendly_name: QCells Cloud Battery usable
        value_template: "{{ 11000 * (max(states('sensor.qcells_cloud_soc') | float(default=0) - 10, 0) / 100) }}"
        unit_of_measurement: W
        device_class: power
# Solar plus usable battery added
      qcells_cloud_solar_plus_battery_total:
        friendly_name: QCells Cloud Solar plus Battery total
        value_template: "{{ states('sensor.qcells_cloud_powerdc_sum') | float + states('sensor.qcells_cloud_battery_usable') | float }}"
        unit_of_measurement: W
        device_class: power
# Battery energy usable
      qcells_cloud_battery_energy_usable:
        friendly_name: QCells Cloud Battery Energy Usable
        value_template: "{{ 11000 * (max(states('sensor.qcells_cloud_soc') | float(default=0) - 10, 0) / 100) }}"
        unit_of_measurement: Wh
        device_class: energy_storage

1a) Checking your code I see you changed the scan interval and added a timeout. The timeout is a good idea - I added that to my code.

1b) Changing the scan interval to 60 sec is no good idea because Solax/Q-Cells Cloud work with 5 min (300 sec) intervals. As I wrote above - I never ever had one single connection problem with the original setting - beside Cloud maintenance on their side. I wouldn’t fire 5 requests if there is one single expected change in that time frame. Waste of resources IMHO.

  1. Beside that you removed some defaults. Don’t know why these should be the reason for connection problems on your side. I did add them for a reason because I experienced empty values during development last year. As they don’t hurt, I would leave them in.

  2. There’s a round instead of a default(0). Ok, can buy that.

Thanks.

Wow, worked straight away!!
Thank you very much!!

@welcomeha Nice script thumbs up

I added it into my HA configuration (or better the freshly installed docker instance) to see much more than the simple Qcells app is offering.

After tweaking and playing around with the script I created a dashboard to display all the essential data:

As you could see on the left side I added the Energy Flow card from here https://github.com/flixlix/energy-flow-card-plus - which is displaying some additional values.

But right now I am struggling with a value showing the daily overall consumption of our house. Basing on the ESS website it should be something around 9,9kWh (bottom right):

This value 9,9kWh is the sum of the values being shown in the Energy Flow pic:

Zuhause 4,87kWh + Battery Usage (discharge total) 5,04kWh:
House_load

The same value is shown inside the HA default energy dashboard:
HA_default_energy

Basing on the other values shown on the default energy dashboard:

this 9,9kWh are the result of:

PV Generation (Solarertrag - sensor.qcells_inverter_dc_pv_power_sum)
18,22

plus

[ battery charge (Batterie - Beladung - sensor.qcells_cloud_battery_charge_kh) = -7,46
+
battery discharge (Batterie - Entladung - sensor.qcells_cloud_battery_discharge_kh) = 5,04]
- 2,46

plus

Netz - Bezug - sensor.qcells_cloud_grid_load_kh = 0,82
+
Netz - Einspeisung - sensor.qcells_cloud_grid_feed_kh = -6,71
-5,89

9,87

So master question to the community/your side - are you able to add such a helper to the script as well?
So I could add another box showing the daily consumption.

Thanks in advance,
Wolf