Hello,
I finally managed to include my SMARTFOX Energy Meter into Home Assistant. Albeit it is an older one, it might be still relevant for somebody else, so I would like to share it. I am not sure about the model, but on my.smartfox.at it shows Version: EMeterHC 12.3.4q
Anyway, it all builds on the idea of using curl to get the data from the IP on the local network, and then dissecting it an putting it to sensors accordingly.
You need to know your Smartfox’s IP address for this.
Make a new file
/config/scripts/smartfox.sh
with the content:
#!/bin/bash
#script to read analog out and relais from smartfox
#curls data, deletes string before and after relevant section, replaces unwanted <>, returns -1 if failed
timeout 25 curl http://192.168.0.54/v_outputs.html | sed 's/.*ANALOGOUT/\nANALOGOUT/' | sed 's/Restlaufzeit.*//' | awk '{gsub(/<[^>]*>/, " "); print}' | sed 's/%.*Status/Status/g' | sed 's/\s\+/;/g' || echo 'ANALOGOUT;-1;Status;-1;-1;-1;-1;'
make it exectuable with:
chmod +x /config/scripty/smartfox.sh
You can try to execute it with ./config/scripts/smartfox.sh
and it should return something like this:
ANALOGAOUT;38;Status;1;1;1;0;
Which would mean that the analog output is at 38% and the relais 1 to 3 are activated, and relais 4 is off. If it can’t be parsed, it will default to -1 for all values.
Add this to the configuration.yaml:
templates:
- name: "smartfox_aout_perc"
unit_of_measurement: "%"
state: "{{ states('sensor.smartfox_raw_data', 'state').split(';')[1] }}"
- name: "smartfox_aout_power"
unit_of_measurement: "W"
#scale up with 100% value of analog load, which is 3800W in this case
state: >-
{% if states('sensor.smartfox_aout_perc') | int >= 0 and states('sensor.smartfox_aout_perc') | int <= 100 %}
{{ (states('sensor.smartfox_aout_perc') | int) * 38 }}
{% else %}
-1
{% endif %}
- name: "smartfox_relais1_state"
state: "{{ states('sensor.smartfox_raw_data', 'state').split(';')[3] }}"
- name: "smartfox_relais2_state"
state: "{{ states('sensor.smartfox_raw_data', 'state').split(';')[4] }}"
- name: "smartfox_relais3_state"
state: "{{ states('sensor.smartfox_raw_data', 'state').split(';')[5] }}"
- name: "smartfox_relais4_state"
state: "{{ states('sensor.smartfox_raw_data', 'state').split(';')[6] }}"
command_line:
- sensor:
name: 'smartfox_raw_data'
command: "/bin/bash /config/scripts/smartfox.sh"
scan_interval: 30 # Adjust the frequency of polling as necessary
That’s it, now there should be the relais states and analog output state available as entities in your home assistant.
It should also be easily adjustable for other use cases. The way I did it was to first try to curl it in the home assitant terminal (can be done from the web with the ssh terminal plugin) and see what is there. Paste this output into ChatGPT and ask it to parse it so that you get the values you want. Be aware that e.g. grep, awk, sed, … are a slimmed-down version of busybox, so some options are not available.
Hope it helps somebody!