Read Sensor with MQTT over internet, not working

Hi, I’m having trouble with my code.
It works fine if I use a local (wifi) IP 192.168.0.xx,
but if I use, as in the code shown here, an IP address on the Internet,
then I receive this error:
[09:44:27][D][mqtt: 180]: Resolving MQTT broker IP address…
[09:44:27][W][mqtt:204]: Couldn’t resolve IP address for ‘http://xxx.50.194.xx/’!
I have static ip, and have made port forward in the router.

code:
'esphome:
’ name: esphome-web-7fa4b7
’ friendly_name: ESPHome_MCPH_Power

'esp8266:
’ board: esp01_1m

'# Enable logging
'logger:

'# Enable Home Assistant API
'api:
’ encryption:
’ key: “xxxxxxxxxxx”

'ota:

'mqtt:
’ broker: http://mqtt://xxx.50.194.xx/ #X hide my real ip, but same format
’ port: 1883
’ username: !secret mqtt_username
’ password: !secret mqtt_password

'binary_sensor:
’ - platform: gpio
’ pin:
’ number: GPIO12
’ mode:
’ input: true
’ pullup: true
’ id: “MCPH”
’ on_press:
’ then:
’ - mqtt.publish:
’ topic: m_cph/ac_state
’ payload: ‘ac_on’
’ on_release:
’ then:
’ - mqtt.publish:
’ topic: m_cph/ac_state
’ payload: ‘ac_off’

'wifi:
’ ssid: !secret wifi_ssid
’ password: !secret wifi_password

’ # Enable fallback hotspot (captive portal) in case wifi connection fails
’ ap:
’ ssid: “Esphome-Web-7Fa4B7”
’ password: “”

'captive_portal:

Why not just

mqtt:
  broker: xxx.50.194.xx

as per the docs? You’ve given it a string which it is interpreting as a domain name and trying to resolve. Also, HTTP is nothing to do with it.

Please format your code correctly in future posts. See here:

Nonsense url. Where did you get this?