Good afternoon all, I have been researching how to ‘use’ some data from scraping an online hub from my MyEnergi hub that controls a Eddi at my house. I have got the following code in my Configuration.YAML file:
# Sensors
sensor:
- platform: rest
name: Eddi
resource: https://s8.myenergi.net/cgi-jstatus-E
device_class: power
scan_interval: 60
timeout: 30
authentication: digest
username: ***********
password: ***********
headers:
User-Agent: Home Assistant
Content-Type: application/json
Accept: application/json
unit_of_measurement: W
value_template: >
{% if value_json.eddi[0].gen is defined %}
{{ value_json.eddi[0].gen }}
{% else %}
0
{% endif %}
json_attributes_path: '$.eddi[0]'
json_attributes:
- dat # Date (UTC)
- tim # Time (UTC)
- ectp1 # Internal CT Value
- ectp2 # Grid CT Value
- ectp3 # Generation CT Value
- ectt1 # Internal CT Name
- ectt2 # Grid CT Name
- ectt3 # Generation CT Name
- frq # Grid Frequency
- vol # Grid Voltage
- zmo # Zappi Mode
- sta # Zappi Status
- pst # Charge Status
- che # KWh Diverted (This Session)
- fwv # Firmware Version
- gen # Generation now
- grd # From Grid Now
It is working, as I can create a sensor in my HA UI that shows the generation, or ‘gen’ as defined above. What I’d like to do is show various bits of data, for example generation, grid supply now, KWh diverted, etc. All of this data is available but the only way I know to ‘change’ the data shown to me is by changing the attribute above in the ‘value_template’ section. Is there a way to ‘read’ all of the data then create different entities based on that data?
PS: Noob here. Only got this working through a lot of trial and error!
Thanks for the quick reply Tony, so I need to re-write my code in the Confi.YAML or is the ‘template sensor’ code that you’ve shown written somewhere else?
Btw, you can split the configuration up into multiple files. There are multiple ways to do this and examples of includes and packages are given in the documentation. I do not recall, maybe someone else can comment, if template sensors can be configured through the UI.
Ok, many thanks for your early assistance with this. From what I understand from the bit of reading I’ve done so far, this specific data i’m grabbing (the MyEnergi ‘Hub’ data) is stored online and can be grabbed using cgi or json or something with the ‘RESTful’ sensor platform. What I really need to to is get ‘something’ to go and grab all the data every 5mins or so, then I can make sensors for the individual bits that I want to show on my UI…
Using your configuration, here is what I would do.
sensor:
- platform: rest
name: Eddi
resource: https://s8.myenergi.net/cgi-jstatus-E
device_class: power
scan_interval: 60
timeout: 30
authentication: digest
username: ***********
password: ***********
headers:
User-Agent: Home Assistant
Content-Type: application/json
Accept: application/json
unit_of_measurement: W
value_template: >
{% if value_json.eddi[0].gen is defined %}
{{ value_json.eddi[0].gen }}
{% else %}
0
{% endif %}
json_attributes_path: '$.eddi[0]'
json_attributes:
- dat # Date (UTC)
- tim # Time (UTC)
- ectp1 # Internal CT Value
- ectp2 # Grid CT Value
- ectp3 # Generation CT Value
- ectt1 # Internal CT Name
- ectt2 # Grid CT Name
- ectt3 # Generation CT Name
- frq # Grid Frequency
- vol # Grid Voltage
- zmo # Zappi Mode
- sta # Zappi Status
- pst # Charge Status
- che # KWh Diverted (This Session)
- fwv # Firmware Version
- gen # Generation now
- grd # From Grid Now
- platform: template
sensors:
eddi_charge_status:
friendly_name: Eddi Charge Status
value_template: "{{ states.sensor.eddi.attributes.pst }}"
eddi_grid_voltage:
friendly_name: Eddi Grid Voltage
unit_of_measure: "V"
device_class: voltage
value_template: "{{ states.sensor.eddi.attributes.vol }}"
icon_template: mdi:transmission-tower
Just a simple example, do check out the documentation for the Template Sensor, you can set the device class (which will influence how the value is displayed and the icon), the unit of measurement, icon, etc…
Tony! Thank you! This is exactly the help I needed. Just this small bit of code is enough for me to get my head around it and continue to tinker. Thanks very much. It makes a lot of sense, and I’ve already got two sensors working. Perfect. Thanks so much.
Basically what you have started. You need the REST sensor to gather all the values with one request, then you the template sensors to expose attribute values you want in the UI or to use directly. As of version 0.115 of Home Assistant Core you can more easily trigger automation and base conditions off attributes of an entity. If you inspect the details of the REST sensor you have created for Eddi in the UI you will see all the attributes listed that are defined.
To adjust how often the REST sensor updates set the scan_interval: value to the number of seconds, 5 minutes being 300 seconds, to influence how often it is updated. Also based on the type of information and if you use template sensors, I would also set force_update: true the the REST sensor so that you have values such as voltage updated even if they did not change.
Personally I use a more generic value for the REST sensor, something that identifies Eddi overall status? You need some value, it could simply be text like Ok.
@mattlivermore could you possibly post your now-working config? I’m trying to do the same as you, get Eddi talking to home assistant. I have looked at some of the examples further up the thread but I must be missing something.
thanks
Ian
I am now using Node-Red to call the MyEnergi API once a minute for my Eddi / Zappi data. I have real time data (5sec updates) from my Sofar inverter giving good usable data. I’m not great with the Node-Red stuff and have had a lot of help in the Facebook group. Feel free to join https://www.facebook.com/groups/2477195449252168
Whilst it’s title indicates it’s a Sofar group (which you may or may not have) - there are some great Node-Red tutorials and then some very useful and customisable Eddi ‘flows’ which are easy to change for your own needs.
What is your level of HA expertise: do you already have sensors up and running? Where have you put the code? Did you restart HA? Is there anything in your logs?