Hi, i’ m novice and i need help to configure a sensor for import power from my 123solar web page using scrape. the page “123solar/programs/programmultilive.php” publish this data:
‘[{“GPTOT”:431.1,“PMAXOTD”:0,“PMAXOTDTIME”:“08:48”}]’
i need to get value after GPTOT in watts
i configure in configuration.yaml
sensor:
I assume you restarted HA to read the new sensor definition?
To check the connection, remove the value_template line, restart, then post a screenshot of the sensor in Developer Tools / States, like this but for your sensor:
I’m out of suggestions then: the value_template line I suggested above ought to pull out the GPTOT value. What does the sensor show with that line back in? Are there any errors in the log?
Apologies: that was in my first attempt for a few seconds before I realised and edited them out. You must have been quick to copy my original response.
your data is in value_json["Dailycounter1"] — there’s no list, so no need for [0].
A counter for energy should have a unit of measurement of Wh or kWh, not W.
Your screenshot suggests that the sensor is picking up a unit of “Kwh” from somewhere, overriding the value in your configuration. This should be kWh.
If you have any control over the PHP script, maybe modify it to output “UK-format” numbers (decimal point not comma, no multipliers): for example, "23480872" instead of "23.480,872 k".
the sensor does not appear, and I do not understand why.
Then, now what should I do to read the value correctly? I mean with the dot?
but it doesn’t show me the value with the dot but in full…
now it is as below:
- platform: rest
resource: http://192.168.1.51/metern/programs/programtotal.php
name: solar consumi totale giornaliero
value_template: '{{ value_json.Dailycounter2 }}'
force_update: true
unit_of_measurement: kWh
device_class: power
Look at your logs. You’ll probably see an error about declaring units of kWh but passing a non-numeric value of 5.9 k. Also, remove the device_class: power as kWh is an energy measurement.
You can’t have two dots in a number. You need to swap dots and commas, or better still remove the thousand separators (dots in EU, commas in UK). Your Totalcounter1, for example, needs to be 23481.958 k. Once you’ve done that, try this as a template if you cannot remove the k multiplier:
value_template: >
{% set v = value_json.Dailycounter2 %}
{% set k = " k" in v %}
{{ v.replace(" k","")|float(0) * (1000 if k else 1) }}
My screenshot shows that it does, for numbers that use no commas and use dots for decimals. Please post the latest PHP output and your latest sensor definition, along with any log errors.
So we are back to dots for thousands and decimal commas . If you can’t get the PHP to feed you real numbers, try this:
value_template: >
{% set v = value_json.Dailycounter2 %}
{% set k = " k" in v %}
{{ v.replace(" k","").replace(".","").replace(",",".")|float(0) * (1000 if k else 1) }}