Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Multiple Input PCS (0xA5) #200

Closed
mjoach opened this issue Oct 31, 2024 · 26 comments · Fixed by #206, scottyphillips/pychonet#77 or #209
Closed

Adding support for Multiple Input PCS (0xA5) #200

mjoach opened this issue Oct 31, 2024 · 26 comments · Fixed by #206, scottyphillips/pychonet#77 or #209
Assignees

Comments

@mjoach
Copy link

mjoach commented Oct 31, 2024

Hi and thank you for all this tremendous work, I was just blown away seeing multiple devices report themselves on my LAN!

I am currently trying to pull solar and battery data from a Nichicon system and it works flawlessly. However, as I found out, the relevant data about current electricity consumption is located only on the Multiple Input PCS (class code 0xA5). It is discovered correctly by the integration and a HASS entity is created, but the only data reported is the operation status. Notably, this device is already supported by pyechonet and I am able to poll attribute values from it without issues with a test pychonet program.

What I did so far is I tried adding this class with the attribute of interest (0xE7, Measured instantaneous amount of electricity) to my /homeassistant/custom_components/echonetlite/const.py, line 992, as shown below.

        0xA3: {  # Lighting system
            0xC0: {  # Set scene
                CONF_ICON: "mdi:palette",
                CONF_TYPE: DEVICE_CLASS_ECHONETLITE_LIGHT_SCENE,
                CONF_STATE_CLASS: SensorStateClass.MEASUREMENT,
                TYPE_NUMBER: {
                    CONF_MAXIMUM: 0xFD,
                    CONF_MAX_OPC: 0xC1,
                },
            },
        },
        
        0xA5: {  # Multiple Input PCS 
            0xE7: {
                CONF_TYPE: SensorDeviceClass.POWER,
                CONF_STATE_CLASS: SensorStateClass.MEASUREMENT,
            },
        },  

However, I did not observe any additional sensors for this entity appear in HASS, despite restarting HASS and removing and re-adding relevant Echonetlite devices.

What am I missing? What else is needed for attributes of this device to become sensors in HASS? For reference, here's the relevant specification for device class 0xA5 (see PDF page 500).
https://echonet.jp/wp/wp-content/uploads/pdf/General/Standard/Release/Release_P/Appendix_Release_P_E.pdf

Thank you in advance for any pointers!

@nao-pon
Copy link
Collaborator

nao-pon commented Dec 26, 2024

We need a class in pychonet that will convert the raw data into a useful value.

For example, HomeSolarPower.py.

And we need to define that class so that the Factory can use it.

https://github.com/scottyphillips/pychonet/blob/93e906055c98df43e48e7449cb3546979474e2fc/pychonet/__init__.py#L44C1-L77C6

@nao-pon
Copy link
Collaborator

nao-pon commented Dec 26, 2024

As mentioned in #205, battery storage and other factors will also be involved in a complex way.

It would be costly to digitize all parameters, so please let us know which parameters you would like to prioritize in order to make them useful for HA.

@nao-pon
Copy link
Collaborator

nao-pon commented Dec 26, 2024

Please try the edge version of my repository. I can't test it, but I've implemented the code.

You can install the edge version by registering as a custom repository in HACS. You can also revert to the original version at any time.

Rel.

@SudarshanKulakrni
Copy link

SudarshanKulakrni commented Dec 27, 2024

Thank you nao-pon san.
I am beginner to Homeassistant, yet to explore HACS and custom repositories.

I have taken your edge version and directly copied to config/custom_component (after taking backup).
Now it has started showing values for 0Xe7 (Measured instantaneous amount of electricity).
I will monitor this value today (looks like a sunny day :)) and will report you the result.

Again thank you very much for late night work !

@SudarshanKulakrni
Copy link

SolarPanel

Hi Nao-Pon san,

I could capture the current status :

  1. Coming from Battery : sensor.solar_measured_instantaneous_charging_discharging_electric_energy
  2. Coming from solar panels : sensor.solar_measured_instantaneous_amount_of_electricity_generated
  3. From PCS : sensor.solar_measured_instantaneous_amount_of_electricity

Actual Nichicon panel, the amount of electricity generated is 2.0 Kw. This is not displayed in any of the 3 entities above.
Its confusing as how Nichicon is calculating this value.

Charging power matches perfectly with 充電 on Battery symbol.

@mjoach
Copy link
Author

mjoach commented Dec 27, 2024

@nao-pon, thank you so much for providing a modified version, I will test it during the holidays.

@SudarshanKulakrni it seems we may have the same Nichicon system. I was able to get all the data from the Nichon panel you pictured, currently by using pychonet directly to query the Multiple Input PCS and feeding results to Home Assistant. However, the data about the instantaneous power consumed by the household appliances (i.e., excluding charging/discharging of the battery) is reported only in an extended field for which I did not find official Echonet specification and is perhaps manufacturer specific. I'll provide more information on that later.

@SudarshanKulakrni
Copy link

@mjoach san, Great to hear that we are using same systems and you were able to get all the data.

How did you use the pychonet directly ?
I mean are there any extra steps other than coping the files from custom_components\echonetlite provided by @nao-pon san.

Btw, another interesting find : There is a App called Echonetscanner for iPhone. If you are on same wifi network as the Solar system, you can see all the properties provided by the devices.
There are few undocumented properties. However, I could not figure out meaning of any of the others, and also could not find any property providing addition of inputs for PCS.

Your input on using the pychonet library to feed value to HA will be greatly appreciated.

@nao-pon
Copy link
Collaborator

nao-pon commented Jan 4, 2025

I was relieved to see that some of the data was retrieved using the code I implemented.

If we can figure out the specifications for retrieving data similar to that of Nichicon control panel, I think it should be possible to retrieve it with a bit of ingenuity.

@SudarshanKulakrni
Copy link

@nao-pon, thank you so much for providing a modified version, I will test it during the holidays.

@SudarshanKulakrni it seems we may have the same Nichicon system. I was able to get all the data from the Nichon panel you pictured, currently by using pychonet directly to query the Multiple Input PCS and feeding results to Home Assistant. However, the data about the instantaneous power consumed by the household appliances (i.e., excluding charging/discharging of the battery) is reported only in an extended field for which I did not find official Echonet specification and is perhaps manufacturer specific. I'll provide more information on that later.

Hi @mjoach It will be great if you can share information on how or use pychonet to query all inputs to PCS, and how did you feed the information to Homeassistant. Appreciate your help !

@mjoach
Copy link
Author

mjoach commented Jan 28, 2025

@nao-pon and @SudarshanKulakrni, I'm sorry for the late reply, life got in the way. I have been testing the edge version for the past couple of days and it is pulling the data from my PCS correctly, thank you for that!

This is, however, where things get somewhat complicated. I noticed that the 3 values reported by the PCS 1) update only when the battery is in a state different than standby 2) do not include the information about the energy consumption of the household itself (just the information about battery charging/discharging). This heavily limits its usefulness as I assume that most users of this system expect to be able to monitor their energy consumption continuously and this is not provided by these fields.

However, when querying Echonet devices on my network, I can see that this Multiple Input PCS, in addition to the 0xe0,0xe3,0xe7 attributes also allows to read attributes 0xf5 and 0xf6.

I wasn't able to find any documentation about them, so by observing what is going on I could see that:
0xf5 is a 16 byte field, where:

  • the first 8 bytes is the instantaneous household energy consumption (W)
  • the second 8 bytes is the instantaneous amount of energy flowing from/to the grid (W)

These are the values normally observed on the LCD monitor of the system.

0xf6 is another 16 byte field, where:

  • the first 8 bytes is the cumulative amount of energy purchased from the grid (Wh)
  • the second 8 bytes is the cumulative amount of energy sold to the grid (Wh)

Now, I think the first questions would be, are these quirks specific to this particular device or is it a newer part of the standard? And if they are not part of the standard, is there a way to manually configure fetching them in HASS?

Finally, @SudarshanKulakrni if you want to skip ahead and try it with your system, I have uploaded my code to feed this data to HASS here:
https://github.com/mjoach/NichiconTribridPCS/
It pulls the data from the PCS and sends it over MQTT to HASS (requires the MQTT addon). I keep it running as a system service on my home server and I can say it has been working without issues since November. However, do note that I had to modify pychonet to make it work, to address the issue explained here:
scottyphillips/pychonet#76

TL;DR for @nao-pon:
Important data is in only present in potentially undocumented fields. Can we make them accessible to HASS?

@SudarshanKulakrni
Copy link

Hi @mjoach That is a wonderful finding on 0xF5 and xF6 ! Genius indeed.
I would like to use the these values to push to HASS.
I wonder how you are using your home server to run Pychonet.
Sorry for a very basic question. Can you please throw some light on how to setup this home server ? Thanks again 🙏

@mjoach
Copy link
Author

mjoach commented Jan 29, 2025

@SudarshanKulakrni, so in case this was unclear, Pychonet is the underlying Python library that this HASS addon relies on. The code I shared with you is just a Python program that is entirely independent from HASS and uses Pychonet library directly to poll the PCS. You can run it on anything that can run Python. I am running it on my Ubuntu home server that is also hosting my Home Assistant installation, as this is the natural choice. Just run the Python program and keep it on 24/7. The only curveball is, however, that rather than install Pychonet via pip, you will have to pull the repository code, modify the line I shared in my previous message and use this altered version until a better approach is devised.

@nao-pon
Copy link
Collaborator

nao-pon commented Jan 31, 2025

@mjoach Thank you for letting us know the useful information!

The quickest way to deal with quirks of each manufacturer is to hard-code them, but there is a concern that this will become unmanageable later, so I think we should think carefully about the specifications and make them extensible. Please give me a little more time.

@SudarshanKulakrni
Copy link

@SudarshanKulakrni, so in case this was unclear, Pychonet is the underlying Python library that this HASS addon relies on. The code I shared with you is just a Python program that is entirely independent from HASS and uses Pychonet library directly to poll the PCS. You can run it on anything that can run Python. I am running it on my Ubuntu home server that is also hosting my Home Assistant installation, as this is the natural choice. Just run the Python program and keep it on 24/7. The only curveball is, however, that rather than install Pychonet via pip, you will have to pull the repository code, modify the line I shared in my previous message and use this altered version until a better approach is devised.

Thank you so much @mjoach for going out of way to write the program.
I finally could setup another Linux laptop (fedora), built and installed the pychonet on fedora with modification you suggested at line 210 of EchonetInstance.py and setup MQTT on HASS,

The code you provided in NichiconPCS2MQTT.py is able to connect to the Broker. I can see the log from this program and log on MQTT on HASS.

However the code fails in EchonetInstance.py, with following traceback, it shows the carets on final line appear below [self._eojgc].

I must be missing something. Have you come across this issue ?
It would be great if you can provide your inputs. Thanks @mjoach

Traceback (most recent call last):
  File "/home/sudarshan/Downloads/nichicon/NichiconTribridPCS-main/NichiconPCS2MQTT.py", line 206, in <module>
    asyncio.run(main(sys.argv))
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ~~~~~~~~~~^^^^^^
  File "/usr/lib64/python3.13/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/usr/lib64/python3.13/asyncio/base_events.py", line 721, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/home/sudarshan/Downloads/nichicon/NichiconTribridPCS-main/NichiconPCS2MQTT.py", line 152, in main
    pcs = Factory(pcs_IP, server, 0x02, 0xA5, 1)
  File "/usr/local/lib/python3.13/site-packages/pychonet-2.6.13-py3.13.egg/pychonet/__init__.py", line 84, in Factory
    return EchonetInstance(host, eojgc, eojcc, eojci, server)
  File "/usr/local/lib/python3.13/site-packages/pychonet-2.6.13-py3.13.egg/pychonet/EchonetInstance.py", line 56, in __init__
    self._epc_data = self._api._state[self._host]["instances"][self._eojgc][
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
KeyError: 2

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 2, 2025

I have merged the PR that addressed the standard Multiple Input PCS. I will also create a new ticket to address the manufacturer's quirks.

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 2, 2025

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 2, 2025

You can try it with the edge version of my repository.
However, I can't test it, so it's unconfirmed. It may not work properly.

Could you please confirm that it works?

@SudarshanKulakrni
Copy link

SudarshanKulakrni commented Feb 3, 2025

Hi @nao-pon さん、

Thank you so much for working on this ! With yesterday's code change I have started getting 2 new entities

  • Energy purchased
  • Energy sold

However values for both the entities are shown as "Unknown".
I tried re-installing the new Echonet edge version by deleting existing entries, restarting the HomeAssistant (even completely re-booting it). Still no values.
I observed the values for one every hour today, but no luck.
@mjoach Btw, Did you get any results ?

Attaching the entities that are displayed for the PCS.
(Measured instantaneous amount of electricity was always showing input from one part, it was not adding the other).

Image

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 3, 2025

I tried to fix the quirks by referring to https://github.com/mjoach/NichiconTribridPCS/blob/main/NichiconPCS2MQTT.py.

Please re-download edge and try again.

@nao-pon nao-pon self-assigned this Feb 7, 2025
@yuina1056
Copy link

yuina1056 commented Feb 7, 2025

hello @nao-pon .
When I tried the edge version in my environment, the following log was output and the entity was not created.

2025-02-07 22:08:14.886 WARNING (MainThread) [custom_components.echonetlite] [0x2(2)-0x6b(107)-0xd9(217)] - Unable to resolve the item name. Please report the unknown code [0x2(2)-0x6b(107)-0xd9(217)] at the issue tracker on GitHub!

Image


私の環境ですと、edgeを利用して再ダウンロード後、エンティティがデバイスを再登録しても出てこない状態です。

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 9, 2025

@yuina1056 Is the PCS manufacturer Nichicon? This does not apply to any other manufacturer than Nichicon, but in any case, if you could attach a debug log showing how the HA starts up completely, i can determine whether it is possible to support the product.

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 9, 2025

We are currently debugging and testing in #209. If you are able to join, please join us there.

@yuina1056
Copy link

@nao-pon

Is the PCS manufacturer Nichicon?

Yes, it is a Nichicon PCS. The model number is ES-R6. This is a Nichicon Tribrid.
eoj is 0x02a501. edge should be usable.

Help with debugging #209 .

@yuina1056
Copy link

This is the debug log at startup.
home-assistant_echonetlite_2025-02-09T13-47-21.216Z.log

Thank you for your help.

@nao-pon
Copy link
Collaborator

nao-pon commented Feb 9, 2025

I had ChatGPT format the relevant part. Looking at "getmap", unfortunately, it seems that the data at 0xF5 and 0xF6 cannot be obtained on this model.

{
  "eojcc": 0xA5,
  "eojci": 0x01,
  "eojgc": 0x02,
  "getmap": [
    0x80, 0x81, 0x82, 0x83, 0x86, 0x88, 0x89, 0x8A, 0x8C, 0x8D,  
    0x93, 0x97, 0x98, 0x9D, 0x9E, 0x9F, 0xD0, 0xE0, 0xE3, 0xE7, 0xE8
  ],
  "host": "192.168.0.5",
  "host_product_code": null,
  "manufacturer": "Nichicon",
  "name": null,
  "ntfmap": [0x80, 0x81, 0x88],
  "setmap": [0x81, 0x93, 0x97, 0x98],
  "uid": "00006c30303030313930343442393346",
  "uidi": "00006c30303030313930343442393346-2-165-1"
}

@yuina1056
Copy link

Thank you for confirming.
Furthermore, each product seems to have its own quirks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants