Help with ZMAI-90 and ESPHome or Tasmota

Ok, after a while, I’ve updated my ESPHome and my old code stopped working. Any tips?
This is my current configuration (was using ‘text_sensor’, changed to new code in this thread, still not working)

esphome:
  name: medidor_energia_adsb
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: "Skynet"
  password: !secret wifi_skynet_pwd
  manual_ip:
    static_ip: 192.168.22.42
    gateway: 192.168.22.1
    subnet: 255.255.255.0    
  

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Medidor Energia Adsb"
    password: "JunhgKtFu2z7"

captive_portal:

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80
  auth:
    username: jmaurin
    password: !secret web_server_pwd


uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 9600
  #parity: EVEN


external_components:
  - source: github://dentra/esphome@tuya-raw-fix
    components: ["tuya"]
  - source: github://dentra/esphome-components  

# Example configuration entry
time:
  - platform: homeassistant
    id: homeassistant_time

# Register the Tuya MCU connection
tuya:
  on_datapoint_update:
    - sensor_datapoint: 6
      datapoint_type: raw
      then:
        - lambda: |-
            id(voltage).publish_state((x[0] << 8 | x[1]) * 0.1);
            id(current).publish_state((x[3] << 8 | x[4]) * 0.001);
            id(power).publish_state((x[6] << 8 | x[7]) * 0.1); 

#text_sensor:
#  - platform: tuya
#    id: tuya_raw_test
#    sensor_datapoint: 6
#    on_value:
#      lambda: |
#        auto d = tuya::rawdecode(x);
#        id(voltage).publish_state((d[0] << 8 | d[1]) * 0.1);
#        id(current).publish_state((d[3] << 8 | d[4]) * 0.001);
#        id(power).publish_state((d[6] << 8 | d[7]));
        
        
        
        
sensor:
  - platform: "tuya"
    id: total
    name: "Energy Total"
    sensor_datapoint: 1
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
    unit_of_measurement: "kWh"
    icon: "mdi:sigma"
    device_class: "energy"
  - platform: template
    id: voltage
    name: "Voltage"
    unit_of_measurement: "V"
    icon: "mdi:sine-wave"
    device_class: "voltage"
  - platform: template
    id: current
    name: "Current"
    unit_of_measurement: "A"
    icon: "mdi:current-ac"
    device_class: "current"
  - platform: template
    id: power
    name: "Active Power"
    unit_of_measurement: "W"
    accuracy_decimals: 0
    icon: "mdi:flash"
    device_class: "power"
  - platform: "energy_monitoring"
    power: power
    voltage: voltage
    current: current
    apparent_power:
      name: "Apparent Power"
    reactive_power:
      name: "Reactive Power"
    power_factor:
      name: "Power Factor"  
    
switch:
   - platform: "tuya"
     name: "Power"
     switch_datapoint: 16
     icon: "mdi:power"

And this is the error while validating or compiling:

INFO Reading configuration /config/esphome/medidor_energia_adsb.yaml...
INFO Updating https://github.com/dentra/esphome.git@tuya-raw-fix
INFO Updating https://github.com/dentra/esphome-components.git@None
ERROR Unable to import component tuya:
Traceback (most recent call last):
  File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/esphome/.esphome/external_components/0091618c/esphome/components/tuya/__init__.py", line 6, in <module>
    from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT
ImportError: cannot import name 'CONF_SENSOR_DATAPOINT' from 'esphome.const' (/opt/esphome/esphome/const.py)
ERROR Unable to import component tuya.sensor:
Traceback (most recent call last):
  File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/esphome/.esphome/external_components/0091618c/esphome/components/tuya/__init__.py", line 6, in <module>
    from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT
ImportError: cannot import name 'CONF_SENSOR_DATAPOINT' from 'esphome.const' (/opt/esphome/esphome/const.py)
ERROR Unable to import component tuya.switch:
Traceback (most recent call last):
  File "/opt/esphome/esphome/loader.py", line 163, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/esphome/.esphome/external_components/0091618c/esphome/components/tuya/__init__.py", line 6, in <module>
    from esphome.const import CONF_ID, CONF_TIME_ID, CONF_TRIGGER_ID, CONF_SENSOR_DATAPOINT
ImportError: cannot import name 'CONF_SENSOR_DATAPOINT' from 'esphome.const' (/opt/esphome/esphome/const.py)
WARNING 'medidor_energia_adsb': Using the '_' (underscore) character in the hostname is discouraged as it can cause problems with some DHCP and local name services. For more information, see https://esphome.io/guides/faq.html#why-shouldn-t-i-use-underscores-in-my-device-name
INFO Detected timezone 'TZ' with UTC offset -3
Failed config

tuya: [source /config/esphome/medidor_energia_adsb.yaml:57]
  
  Component not found: tuya.
  on_datapoint_update: 
    - sensor_datapoint: 6
      datapoint_type: raw
      then: 
        - lambda: |-
            id(voltage).publish_state((x[0] << 8 | x[1]) * 0.1);
            id(current).publish_state((x[3] << 8 | x[4]) * 0.001);
            id(power).publish_state((x[6] << 8 | x[7]) * 0.1); 
sensor.tuya: [source /config/esphome/medidor_energia_adsb.yaml:81]
  
  Platform not found: 'sensor.tuya'.
  platform: tuya
  id: total
  name: Energy Total
  sensor_datapoint: 1
  accuracy_decimals: 3
  filters: 
    - multiply: 0.001
  unit_of_measurement: kWh
  icon: mdi:sigma
  device_class: energy
switch.tuya: [source /config/esphome/medidor_energia_adsb.yaml:122]
  
  Platform not found: 'switch.tuya'.
  platform: tuya
  name: Power
  switch_datapoint: 16
  icon: mdi:power

Forgot to say, I’m using v2021.8.2

I made a fix for support loading via external components. Please use special branch tuya-raw-fix-standalone

external_components:
  - source: github://dentra/esphome@tuya-raw-fix-standalone
    components: ["tuya"]

tks, it worked!!

JFYI, I had to disable energy_monitoring modules.

Compiling /data/medidor_energia_adsb/.pioenvs/medidor_energia_adsb/src/esphome/components/api/util.cpp.o
Compiling /data/medidor_energia_adsb/.pioenvs/medidor_energia_adsb/src/esphome/components/captive_portal/captive_portal.cpp.o
Compiling /data/medidor_energia_adsb/.pioenvs/medidor_energia_adsb/src/esphome/components/energy_monitoring/energy_monitoring.cpp.o
Compiling /data/medidor_energia_adsb/.pioenvs/medidor_energia_adsb/src/esphome/components/homeassistant/time/homeassistant_time.cpp.o
In file included from src/esphome/core/esphal.h:3:0,
                 from src/esphome/core/log.h:12,
                 from src/esphome/components/energy_monitoring/energy_monitoring.cpp:3:
/root/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/random.tcc: In member function 'void std::poisson_distribution<_IntType>::param_type::_M_initialize()':
/root/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Arduino.h:137:22: error: expected unqualified-id before '(' token
 #define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
                      ^
/root/.platformio/packages/toolchain-xtensa/xtensa-lx106-elf/include/c++/4.8.2/bits/random.tcc: In member function 'void std::binomial_distribution<_IntType>::param_type::_M_initialize()':
/root/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Arduino.h:137:22: error: expected unqualified-id before '(' token
 #define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
                      ^
/root/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Arduino.h:137:22: error: expected unqualified-id before '(' token
 #define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
                      ^
*** [/data/medidor_energia_adsb/.pioenvs/medidor_energia_adsb/src/esphome/components/energy_monitoring/energy_monitoring.cpp.o] Error 1

energy_monitoring fixed

tks, working again!
:+1:

Starting with 2021.12.0 this feature is included directly to ESPHome

Hi, I’m not sure if this is the right place to ask, but it seems that there’s a lot of similar info to what I think I need. I’ve got a ZMAi-90, I think it’s a newer version as it has the CBU unit inside (I’ve opened it). From what I understand this is not flashable. That said, with localtuya alone it is giving me apparently useful information which appears to represent the info that I’m after with the exception of the W/V/A.


From the discussion above it appears that there’s a way to convert the text string in DP6 in to the W/V/A info, but is this restricted to only ESPHome/Tasmota flashed units or is there a way I can get homeassistant to do the decoding with my stock firmware unit? (by decoding it into template sensors in configuration.yaml?)
Cheers, Matt.

I think that with a bit of work the DP17 can also be decoded as it appears to be the over current/over voltage/under voltage/kWh Balance warning setpoints and alarm on/off settings.

@mtpduggan why not? You could use python_script to read localtuya sensor, transform and output to template sensors.

@dentra If you’re still interested, (by a process of elimination) here’s what I believe to be the structure for DP17.

0A0BBB0C0DDD0E0FFF0G0HHH
A = Over Current Control Switch (1-on, 0=0ff)
B = Over Current Control Value (In Amps)
C = Over Voltage Control Switch (1-on, 0=0ff)
D = Over Voltage Control Value (in Volts)
E = Under Voltage Control Switch (1-on, 0=0ff)
F = Under Voltage Control Value (in Volts)
G = Insufficient Balance Control Switch (1-on, 0=0ff)
H = Insufficient Balance Control Val (in kWh)

From the example values you had, yours is a shorter string as you probably don’t have the balance control part in your unit.

If anyone else has stumbled upon this and is interested, then DP17 only gets a value once it’s been used (ie by using the phone app to set the values). If you’re not detecting this DP with config flow and you want to add it in, then it’s possible to add via a mod to your core.config_entries in /home/homeassistant/.homeassistant/.storage
I haven’t a clue if that’s an official way or not but found it by messing…

Done some further digging, DP17 looks a little more complicated than I previously had above.

HEX formatted 0A0B0CCC0D0E0FFF0G0H0III0J0K0LLL (e.g. 0100003c03000105040000b508000014), where:
A = Value1 (?)
B = Over Current Control Switch (1-on, 0=0ff)
C = Over Current Control Value (In Amps)
D = Value2 (?)
E = Over Voltage Control Switch (1-on, 0=0ff)
F = Over Voltage Control Value (in Volts)
G = Value3 (?)
H = Under Voltage Control Switch (1-on, 0=0ff)
I = Under Voltage Control Value (in Volts)
J = Value4 (?)
K = Insufficient Balance Control Switch (1-on, 0=0ff)
L = Insufficient Balance Control Val (in kWh)
J?, K & L may not be implemented on some ZMAi-90 models.

A, D, G & J are probably* some form of status signals that indicate the state of the trip/alarm
B, E, H & K are the toggle bits to enable the alarm
C, F, I & L are the respective values of the alarm

*Unfortunately I’ve now got mine installed and now can’t trip them for testing as it’ll mean I lose power to my router and pi.

edit:-
I’ve just been investigating further and uncovered a few states for DP10:-
1 - Unit tripped on over current
4 - Unit tripped on over voltage
8 - Unit tripped on under voltage
512 - Seems to come up with Under Balance, so would expect to be an under balance trip

Hello.
I would like to provide you with very simple instructions. The method works and is proven. I did so a few devices.

Hi there! I also have CBU version.

I got following from API:

{ "result": { "category": "zndb", "functions": [ 
{ "code": "switch_prepayment", "dp_id": 12, "type": "Boolean", "values": "{}" }, 
{ "code": "clear_energy", "dp_id": 14, "type": "Boolean", "values": "{}" }, 
{ "code": "charge_energy", "dp_id": 15, "type": "Integer", "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":50000,\"scale\":0,\"step\":1}" }, 
{ "code": "switch", "dp_id": 16, "type": "Boolean", "values": "{}" }, { "code": "alarm_set_2", "dp_id": 17, "type": "Json", "values": "{}" }, 
{ "code": "event_clear", "dp_id": 20, "type": "Boolean", "values": "{}" } ], "status": [ 
{ "code": "forward_energy_total", "dp_id": 1, "type": "Integer", "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}" }, 
{ "code": "phase_a", "dp_id": 6, "type": "Json", "values": "{}" }, 
{ "code": "fault", "dp_id": 10, "type": "Bitmap", "values": "{\"label\":[\"ov_cr\",\"unbalance_alarm\",\"ov_vol\",\"undervoltage_alarm\",\"miss_phase_alarm\",\"outage_alarm\",\"magnetism_alarm\",\"terminal_alarm\",\"cover_alarm\",\"credit_alarm\",\"no_balance_alarm\",\"battery_alarm\",\"meter_hardware_alarm\"]}" }, 
{ "code": "switch_prepayment", "dp_id": 12, "type": "Boolean", "values": "{}" }, 
{ "code": "balance_energy", "dp_id": 13, "type": "Integer", "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":99999999,\"scale\":2,\"step\":1}" }, 
{ "code": "clear_energy", "dp_id": 14, "type": "Boolean", "values": "{}" }, 
{ "code": "charge_energy", "dp_id": 15, "type": "Integer", "values": "{\"unit\":\"kW·h\",\"min\":0,\"max\":50000,\"scale\":0,\"step\":1}" }, 
{ "code": "switch", "dp_id": 16, "type": "Boolean", "values": "{}" }, { "code": "alarm_set_2", "dp_id": 17, "type": "Json", "values": "{}" }, 
{ "code": "event_clear", "dp_id": 20, "type": "Boolean", "values": "{}" } ] }, "success": true, "t": 1655040556587, "tid": "a8210ba7ea5311ec87382aa367714e21" }

But I can not get DP ID 6 in local tuya during integration setup. Did you decoded that value?

Hi,
Sorry it’s taken so long to reply. It rarely picks up DP ID 6 with the automated flow configuration, but you can manually configure it.
If you can find your core.config_entries file - located in /home/homeassistant/.homeassistant/.storage/
You need to manually edit it, (make a copy first just in case), but if you scroll down to the bottom you’ll hopefully see the config that it’s generated when you originally set up the ZMAI-90, so you add the config lines for ID 6. Mine is this.

                        {
                            "friendly_name": "Smart_Meter_06",
                            "id": 6,
                            "platform": "sensor"
                        },

Once you’ve got that you can monitor it and see if you’re getting data from it, hopefully you’ll see something like CaEAFrIABYc= which will indicate that it’s working. It might take a minute to get valid data.

If that works, then next create a file called /home/homeassistant/.homeassistant/python_scripts/base64_int.py containing the next code (create the directory if required). This is some python code that will decode the above data string into something you can work with.

#!/usr/bin/env python3
import base64
import sys
import struct

data = sys.argv[1]
#if len(sys.argv) >= 3:
#    length = int(sys.argv[2])
#    data = data[:length]

# Python 2
value =  base64.b64decode(data).encode('hex')
# Python 3
#value = base64.b64decode(data).hex()

print(value)

Then add the following into /home/homeassistant/.homeassistant/configuration.yaml which will create the sensors you need to show the Volts/Amps/Watts.

sensor:
  - platform: command_line
    name: smartmeter_dp6
    command: "python /home/homeassistant/.homeassistant/python_scripts/base64_int.py {{ states('sensor.smart_meter_06') }}" 
  - platform: template 
    sensors: 
      smartmeter_voltage: 
       value_template: "{{(states.sensor.smartmeter_dp6.state.split('.')[0][0:4])|int(base=16)*0.1}}" 
       friendly_name: 'Volts'
      smartmeter_current: 
       value_template: "{{(states.sensor.smartmeter_dp6.state.split('.')[0][6:10])|int(base=16)*0.001}}" 
       friendly_name: 'Amps'
      smartmeter_power: 
       value_template: "{{(states.sensor.smartmeter_dp6.state.split('.')[0][12:16])|int(base=16)}}" 
       friendly_name: 'Watts'

If anyone reading is better at coding than me, unfortunately I had to learn while doing this so then feel free to offer any improvements as I’m sure there are more elegant ways of doing this and it could probably do with some error trapping on startup while it’s waiting for valid data.

Awesome! Thank you!

Got some troubles with config…

2022-06-14 22:24:29 ERROR (MainThread) [homeassistant.helpers.event] Error while processing template: Template("{{(states.sensor.smartmeter_dp6.state.split('.')[0][0:4])|int(base=16)*0.1}}")
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 409, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1842, in _render_with_context
    return template.render(**kwargs)
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/usr/local/lib/python3.9/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1634, in forgiving_int_filter
    raise_no_default("int", value)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 1331, in raise_no_default
    raise ValueError(
ValueError: Template error: int got invalid input 'unkn' when rendering template '{{(states.sensor.smartmeter_dp6.state.split('.')[0][0:4])|int(base=16)*0.1}}' but no default was specified

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 525, in async_render_to_info
    render_info._result = self.async_render(variables, strict=strict, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 411, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: ValueError: Template error: int got invalid input 'unkn' when rendering template '{{(states.sensor.smartmeter_dp6.state.split('.')[0][0:4])|int(base=16)*0.1}}' but no default was specified

Seems that python script seems nothing at input or output… smartmeter_dp6 status in “unknown”. When I run script from CLI and set Smart_Meter_06 state “CO8AE8QABCE=” - is answers me “08ef0013c4000421”.

Hi, are you getting good data from the id 6 data point? Mine does throw errors/warnings when it starts as the command line is initially being passed unknown/invalid info but once the id data gets read in it works OK, so after a couple of minutes you should have seen something.
With regards to the script, it looks as though it is doing what it’s supposed to if you’re getting a response. If you can open two homeassistant windows at the same time, one showing the new V/A/W sensors and one in developer tools. In developer tools entities tab, find your initial dp6 data (sensor.smart_meter_06) was mine then pop your CO8AE8QABCE= in the state field and set it. That should then give the command line sensor valid data for the script and hopefully you’ll see it give you some values for V/A/W, although it might disappear if invalid data then comes back through.


This is what I get on my test card when I force your value in.

type: entities
entities:
  - entity: sensor.smart_meter_06
  - entity: sensor.smartmeter_dp6
    name: decoded
  - entity: sensor.smartmeter_voltage
  - entity: sensor.smartmeter_current
  - entity: sensor.smartmeter_power
title: Smart Meter DP6 (Volts/Amps/Watts)

If you want to try that card use the above code that I had for diagnostics.

If it works, it suggests that id6 isn’t getting the expected data from the meter, although the fact that you’ve given me a value in your reply makes me think you are getting good data.
If that doesn’t work there are a couple of things to check using that card (otherwise)

  1. Once you’ve got valid data in the first entity, do you get a decoded value? If not then check your python version or maybe just change the commenting on the last part of python decoding script to get it to use python 3.
  2. how are you doing the CLI as that seemed to work? It might be that you’re logging in to a session as a different user than the homeassistant instance which would flag that homeassistant doesn’t have rights to execute the script so you’d have to change the rights.
  3. there was also something I remember doing in my config.yaml with regards to permitting certain folders to be accessed (allowlist_external_dirs), but I think that was for different command line sensors I was using.
    Let me know how you get on.

If I run script from Debian I get:

root@HASSIO:/usr/share/hassio/homeassistant/python_scripts# python base64_int.py CO8AE8QABCE=
08ef0013c4000421
root@HASSIO:/usr/share/hassio/homeassistant/python_scripts#

Here is manually set value for [sensor.smartmeter_dp6]


This is usual state if value was not set.

Seems that Python script does not return vale to [sensor.smartmeter_dp6].

Maybe there is trouble with path to script?

Hi, maybe try these couple of tests with the Python decoding script.

#!/usr/bin/env python3
import base64
import sys

data = sys.argv[1]
#data = "CO8AE8QABCE="                    #Test 2

# Python 2
value =  base64.b64decode(data).encode('hex')                  #Test 3
# Python 3
#value = base64.b64decode(data).hex()                               #Test 3
value = 08ef0013c4000421                  #Test 1

print(value)

The first one is already uncommented, it will prove whether the python script is actually being called rather than any of the logic in the code as it’s bacically giving a vaild data straight to the output.
If that doesn’t then we need to check out why the script call isn’t working.
If you do get a value back in your test windows, then comment out the first test and uncomment the second test and it’ll test if the conversion code is working.
If that doesn’t work then try changing/swapping the commenting out on the two test 3 lines. There’s a chance that if you’re up to date this might be the issue as you’re likely to be running Python 3. I’m not sure why mine isn’t so I stuck with the Python 2 calc for this until I’ve bottomed it out.
If the script isn’t being called, then yes check the path that you’re using in the command line call to make sure it’s correct. There does appear to be adifference in your command line call path so this could be the issue. You might need

    command: "python /usr/share/hassio/homeassistant/python_scripts/base64_int.py {{ states('sensor.smart_meter_06') }}"

If that’s ok then there’s the possibility that the permissions on the script file is wrong (although this might only apply to shell scripts.) I know with mine that when I SSH in to the pi I’m running on I use an admin account and it’s then a different account that homeassistant uses. As such if you’re doing the same sort of thing, then the admin account will have created the script and the homeassistant account might not be allowed to run it.
If you SSH in and try ls -la and see what you get. My install is as follows.

pi@raspberrypi:/home/homeassistant/.homeassistant/python_scripts $ ls -la
total 20
drwxr-xr-x  2 homeassistant root          4096 Mar 30 16:24  .
drwxr-xr-x 12 homeassistant homeassistant 4096 Jun 15 10:21  ..
-rw-r--r--  1 homeassistant root           318 Jun 15 11:07  base64_int.py

You could try chmod and chown to match mine as another test, but as I said, I don’t think it’s likely to be this as it’s python.

Another things to check although it mightn’t be an issue, originally I thought that running the python script needed python_script: in my config.yaml, but it doesn’t (as it’s a direct command line call to Python) so that’s now #'d out.

Just to add, one final thing with the path you’re using, if it’s external to the homeassistant environment then you might need to add something like this to your configuration.yaml, but obviously with your path rather than mine

  allowlist_external_dirs:
    - "/home/homeassistant/.homeassistant/solar/"
    - "/tmp"
    - "/temp"

Possibly this?:

  allowlist_external_dirs:
    - "/usr/share/hassio/homeassistant/python_scripts/"

Anyway, hopefully something above gives a clue as I’m starting to draw blanks!