Anyone managed to integrate eToro to HA?
It would be nice to take take a periodic reading of my account and save the details in HA.
this thread explains how to extract info through API … I guess a REST sensor will do the trick but I have no idea how to implement it
1 Like
RESTful integration should do the trick indeed
I briefly looked at the data and I assume you would need a sensor per instrumentID so if these are stable then that should work
can you guide me how to build the sensors for the instrument ID?
It should (!) be something as per below but the site is rejecting the rest request (not allowed). So if you have another way to access/download the data then we can have a further look
sensor:
- platform: rest
name: testing
scan_interval: 3600
resource: "https://www.etoro.com/sapi/trade-data-real/live/public/portfolios?format=json&cid=3180395"
value_template: "OK"
json_attributes:
- AggregatedPositions
As an example for when you have proper access to the data…
I put the data in a file in folder www, called testing.json (arbitrary)
The used this:
- platform: rest
name: testing2
scan_interval: 3600
resource: "http://192.168.1.20:8124/local/testing.json"
value_template: "{{ value_json.AggregatedPositions.0.NetProfit }}"
json_attributes_path: $.AggregatedPositions.0
json_attributes:
- Direction
Which gives me:
EDIT: So the 0 in the path points to the first group in AggregatedPositions… as the InstrumentID is not a group one has to extract 0 as a sensor, then 1 …etc… hence me mentioning that the resultset should be stable.
Note that one can e.g. use the InstrumentID as State to identify the individual sensors
thanks … i thought that it would be possible to use the text returned when using your URL in a web browser, and parse it into sensors.
thanks, will take a look at your suggestions and revert!
can you maybe put the value_template in the first example shown in this and create sensors?
One can do a lot … but I cannot get the data through the website, this is part of the debug log
<span class="error-description">Access denied</span>
<span class="code-label">Error code <span>1020</span></span>
</h1>
<div class="large-font">
<p>You do not have access to www.etoro.com.</p><p>The site owner may have set restrictions that prevent you from accessing the site. Contact the site owner for access or try loading the page again.</p>
</div>
</div>
</div>
<div>
<div class="clearfix section">
<div class="column know-more">
<h2 class="large-font">Additional information</h2>
<p>The access policies of a site define which visits are allowed. Your current visit is not allowed according to those policies.</p><p>Only the site owner can change site access policies.</p>
</div>
So… although I can;t care less about eToro… I was interested in the access issue and managed to circumvent it … learning-moment for me too
So… below works, produces the first two sensor/InstrumentID from the page
rest:
- authentication: basic
scan_interval: 3600
verify_ssl: false
headers:
Content-Type: application/json
User-Agent: Home Assistant
Accept-Encoding: identity
resource: "https://www.etoro.com/sapi/trade-data-real/live/public/portfolios?format=json&cid=3180395"
sensor:
- name: ID0
value_template: "{{ value_json.AggregatedPositions.0.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.0
json_attributes:
- NetProfit
- Direction
- name: ID1
value_template: "{{ value_json.AggregatedPositions.1.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.1
json_attributes:
- NetProfit
- Direction
1 Like
great! I was very near but didnt manage to make it work!
will try it out tomorrow and will let you know how it goes!
Just tried it now … a direct copy and paste of your code so that first I try to understand what is going on but it is not working
does it normally update immediately after HA restart?
Odd… can you please add this to the logger section in configyaml and restart?
homeassistant.components.rest: debug
I just extended it with two new sections…all fine
rest:
- authentication: basic
scan_interval: 3600
verify_ssl: false
headers:
Content-Type: application/json
User-Agent: Home Assistant
Accept-Encoding: identity
resource: "https://www.etoro.com/sapi/trade-data-real/live/public/portfolios?format=json&cid=3180395"
sensor:
- name: ID0
value_template: "{{ value_json.AggregatedPositions.0.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.0
json_attributes:
- NetProfit
- Direction
- name: ID1
value_template: "{{ value_json.AggregatedPositions.1.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.1
json_attributes:
- NetProfit
- Direction
- name: ID2
value_template: "{{ value_json.AggregatedPositions.2.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.2
json_attributes:
- NetProfit
- Direction
- name: ID3
value_template: "{{ value_json.AggregatedPositions.3.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.3
json_attributes:
- NetProfit
- Direction
I checked this morning and now it is OK without doing any changes … i think I had to wait a bit more
can you maybe what the following really mean? because my account it slightly different from the one being used in your example:
value_template: "{{ value_json.AggregatedPositions.0.InstrumentID }}"
json_attributes_path: $.AggregatedPositions.0
sorted mate … understood how it is working!
thanks!
Ah, I thought your portfolio was made public …
use a json viewer (if not already done so) e.g. Online JSON Viewer (stack.hu)
1 Like
thanks managed to do what I need.
this is unrelated but I would like to avoid opening a new thread. now I renamed the sensor name but the old ones are still in HA and cannot be deleted (grayed out) will these be removed automatically?
I only try things out on a dev instance that I refresh to my liking … having a container setup this is pretty easy
so there is not way to remove it?