MQTT state: extract integer from String

Hi all,
i’m using a mod firmware for my mqtt cover and i receive this state
Received message on stat/sonoff02/RESULT: b'{"Cover1":8}'

How i can extract the number 8 ?
Also i don’t understand why the sensor is reported as unknown.

image

I receive this log
2018-04-18 00:11:08 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on tele/sonoff02/LWT: b'Online'

firmware:
https://github.com/kabongsteve/Sonoff-Tasmota

my actual code is

  - platform: mqtt
    state_topic: "stat/sonoff02/RESULT"
    command_topic: "cmnd/sonoff02/Backlog"
    availability_topic: "tele/sonoff02/LWT"
 #       command_topic: "cmnd/sonoff01/power"
#    state_topic: "stat/sonoff01/POWER"
    name: "Tenda 1"
    qos: 0
    retain: true
    payload_open: "cover ON"
    payload_close: "cover OFF"
    payload_stop: "cover 3"
    state_open: "ON"
    state_closed: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    optimistic: false
    value_template: "{{ value.x }}"
    tilt_command_topic: "cmnd/sonoff02/COVER"
    tilt_status_topic: "stat/sonoff02/RESULT"
    set_position_topic: "cmnd/sonoff02/COVER"
    tilt_min: 5
    tilt_max: 100
    tilt_closed_value: 20
    tilt_opened_value: 50

Thanks

This is a json payload, so you need to use the template mechanism to process that. See

something like

value_template: '{{value_json.Cover1}}'

Should work

It don’t works very well
I see this message on logs
2018-04-18 16:23:30 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on stat/sonoff02/RESULT: b’{“Cover1”:34}’
2018-04-18 16:23:39 ERROR (MainThread) [homeassistant.components.cover.mqtt] UndefinedError: ‘value_json’ is undefined

set_position_template: '{{ value_json.Cover1 }}'

The set_position_template seems to be for an outgoing message, and I have no experience with these, so I can’t really help.

The two lines in the log extract are 9s apart, so are unlikely to be directly related - even on the slowest computer.

What exactly are you trying to do?