Energenie MiHome component

The switch can store two different codes, so you can use two different remotes to control it. You can make up codes for use from the PiMote, but there are rules that have to be met in the signal. I think I found out what they were when I was writing engMQTTclient, but I have long since forgotten. I may have them written down in the documentation. I listen for the remote code and just use that.

I use OpenMQTTGateway to listen for signals, but any 433Mhz snooper should do the job.

Not directly, but if you configure a switch to send the code, it will be sent . when you turn the switch on.

I can’t help there, I live in a rural market town. But the signal strength is attenuated by walls, and there are plenty of codes, so I don’t think it would be a problem.

Yes, and I was surprised it worked. I just copied the code the the remote sent and used it in the MQTT message, but there is no guarantee it will work for anything else. There are different protocols used by different manufacturers, and not all of them are compatible.

1 Like

Hi Steve you seem to be the go to man on the home assistant, energenie, command line subject and wondered if you could cast any light on my problem?
I have an energenie thermostat which i can switch on and off in home assistant with the code below

- platform: command_line
    switches:
      greathall_thermostat_switch:
        command_on: 'curl -u "username@password" -X POST -H "Content-Type: application/json" -d "{\"id\":188722}" https://mihome4u.co.uk/api/v1/subdevices/power_on'
        command_off: 'curl -u "username@password?" -X POST -H "Content-Type: application/json" -d "{\"id\":188722}" https://mihome4u.co.uk/api/v1/subdevices/power_off'
        #command_state: 'curl -u "username@password?" -X GET -H "Content-Type: application/json" -d "{\"id\":188722}" https://mihome4u.co.uk/api/v1/subdevices/show'
        #value_template: '{{ value_json.data.power_state == "1" }}'
        friendly_name: Greathall Thermostat Switch

As you can see i have hashed out the command_state and value_template as these are not returning the state of the relay and make the switch return to off after it is switched on.
Any help appreciated

Apologies for not replying I haven’t done much with Energenie for a long time. I’m guessing you are trying to do a switch that turns on and off your thermostat which is the part that is uncommented.
I think the part that is commented should actually be a sensor not a switch.

Try adding it as a sensor, something like this:

sensor:
  platform: command_line
  command: 'curl -u "username@password?" -X GET -H "Content-Type: application/json" -d "{\"id\":188722}" https://mihome4u.co.uk/api/v1/subdevices/show
  name: Greathall Thermostat State
  value_template: '{{ value_json.data.power_state == "1" }}'

Thanks for the response steve i had got a sensor setup already but it didnt work with the command_line switch, but it does work with the template switch with the following

- platform: template
    switches:
      energenie_greathall_thermostat_switch:
        friendly_name: Energenie Greathall Thermostat Switch
        value_template: "{{ is_state('sensor.greathall_thermostat_switch_state', '1') }}"
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.greathall_thermostat_switch
        turn_off:
          service: switch.turn_off
          data:
            entity_id: switch.greathall_thermostat_switch

Why have energenie not done a Home Assistant component yet?

It would make their products far more desirable!

2 Likes

Hello All

I am still struggling with programming an automation or slider to adjust the temperature of a mihome thermostat

I have the code below which will change the temperature to 25 , howerver how do i incopeate a slider into the code to adjust te temperature

Any Help greatly recieve

paul

`curl -u "YOURUSERNAME;:YOURPASSWORD" -X POST -H "Content-Type: 
application/json" -d "{\"id\":146015, \"temperature\":25.0}" 
https://mihome4u.co.uk/api/v1/subdevices/set_target_temperature`

I’ve been using the HTTP POST commands as posted by StevenHorner further up this thread (thanks!). However I’ve noticed that the switch on/off commands are no longer working in ny HA setup. I can still turn them off from the Energenie web console, and have re-checked my device ID’s against the Energenie console, but my Home Assistant commands are no longer triggering the switches.
Here’s an example of one of my commands (with id’s substituted):

study_switch:
        command_on: 'curl -u "[email protected]:mypassword" -X POST -H "Content-Type: application/json" -d "{\"id\":12345}" https://mihome4u.co.uk/api/v1/subdevices/power_on --insecure'

Is anyone else having problems with this at the moment?
I’m running an HA 0.65.0

Hi Steve,

Can I add my thanks to others for your examples?

I am becoming more and more sold on HASS due to the wonderful helpful community including guys like you.

Best regards Peter

Is it possible to get the current state of energenie switches such that the HA UI shows the correct state?
I’m pretty new to this but using the mihome api and the curl command as described above I have my light and plug switches working in that I can turn them on/off. (So thanks for the info) But, if the switch is triggered by something else, say I actually press the physical button, the HA UI becomes out of sync - even when refreshed. I know there is a api to get current state, but is it possible to integrate this into HA Ui some how?
Thanks

Thank you!
I accidentally bought one of these thinking it was tuya-based, and at least I can control it for the few weeks I need it and then can send it back when I can access my already tasmotised plugs.

I was using a APIRequest.io to get the details but it kept responding “not found” when controlling devices, but your command just worked as soon as I put in the details.

Hi Paul,

I also have the eTRVs. Did you manage to work out how to parameterise set_target_temperature call with slider or other selection?

I have the below from @stevenhorner working.

curl -u “:” -X POST -H “Content-Type: application/json” -d “{“id”:54321, “temperature”:25.0}” https://mihome4u.co.uk/api/v1/subdevices/set_target_temperature

Many Thanks

I have got this working with the Rest sensors etc, I will post all the code shortly.

1 Like

WORKING EXAMPLE BELOW

Sorry for the delay, I have not completed the full switch yet (will post once complete), but here is the code to get power measurement from the MiHome Smart Plug MIHO005 and MIHO004 and add them to the “Energy” page of home assistant. Using “rest” and “integration” platforms.

The platform: integration will show up in “/developer-tools/statistics” and can be added via “/config/energy”

Set username, password and payload ID (for your switch/sensor) as appropriate.

########################################################################
# MiHome Living Room TV Switch
########################################################################

# Control and Monitor.
# Mi|Home Smart Plug+ MIHO005
  - platform: rest
    name: "MiHome Living Room TV Switch Watts"
    resource: 'https://mihome4u.co.uk/api/v1/subdevices/show'
    method: POST
    authentication: basic
    username: !secret MiHome_ID
    password: !secret MiHome_Password
    payload: '{"id":311088}'
    value_template: '{{ value_json.data.real_power }}'
    unit_of_measurement: W
    device_class: power #Power, watts. Not "Energy" i.e. Wh.
    state_class: measurement
    json_attributes_path: "data"
    json_attributes:
      - label
      - device_id
      - power_state
      - startup_mode
      - device_type
      - remote_id
      - voltage
      - voltage_reported_at
      - frequency
      - real_power
      - today_wh
    headers:
      Content-Type: application/json
    force_update: true
  

# https://www.home-assistant.io/integrations/integration/
# https://community.home-assistant.io/t/powercalc-virtual-power-sensors/318515/3
# https://www.home-assistant.io/integrations/integration/#energy
  - platform: integration
    source: sensor.mihome_living_room_tv_switch_watts
    name: MiHome Living Room TV Switch Energy
    unit_prefix: k
    unit_time: h
    round: 2
    unit: kWh


########################################################################
# MiHome Server Plug
########################################################################

# https://mihome4u.co.uk/devices/37815/subdevices/279158/edit
# Monitor only, has no control.
# Mi|Home Smart Monitor Plug MIHO004
  - platform: rest
    name: "MiHome Server Monitor Plug Watts"
    resource: 'https://mihome4u.co.uk/api/v1/subdevices/show'
    method: POST
    authentication: basic
    username: !secret MiHome_ID
    password: !secret MiHome_Password
    payload: '{"id":279158}'
    value_template: '{{ value_json.data.real_power }}'
    unit_of_measurement: W
    device_class: power #Power, watts. Not "Energy" i.e. Wh.
    state_class: measurement
    json_attributes_path: "data"
    json_attributes:
      - label
      - device_id
      - power_state
      - startup_mode
      - device_type
      - remote_id
      - voltage
      - voltage_reported_at
      - frequency
      - real_power
      - today_wh
    headers:
      Content-Type: application/json
    force_update: true
  

# https://www.home-assistant.io/integrations/integration/
# https://community.home-assistant.io/t/powercalc-virtual-power-sensors/318515/3
# https://www.home-assistant.io/integrations/integration/#energy
  - platform: integration
    source: sensor.mihome_server_monitor_plug_watts
    name: MiHome Sever Monitor Plug Energy
    unit_prefix: k
    unit_time: h
    round: 2
    unit: kWh

Update: I’ve now finished the complete configuration and it’s available here:

1 Like

Hi All very new to home assistant i have about 8eTRV and verious light switchs and sockets and they all connect the Energnie hub and for many years have work great. to start with all i want is to be simple be able to record the temperature in home assistant but i cant find a simple solution to follow. I am also using an old pc to power Home assistant.

Someone please help before i go out of my mind here
this must be a simple mistake i am making
in my configuration.yaml file i have this

#background: var(--background-image)
history:
logbook:
# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:


sensor:

  - platform: command_line
    command: 'curl -u "login :password" -X POST -H "Content-Type: application/json" -d "{\"id\":356528}" https://mihome4u.co.uk/api/v1/subdevices/show'
    name: mbs_radiator
    unit_of_measurement: °C
    value_template: '{{ value_json.data.last_temperature }}'

`
If I do the curl command I get the data back
When i test it in home assistant it says no errors, but when i run it, i get no entity?

Paul

Anyone Please ?