Skip to content

Commit

Permalink
Update athom-smart-plug-v2.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
tarontop authored Mar 25, 2023
1 parent ab76339 commit 1c1fd5b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions athom-smart-plug-v2.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
substitutions:
device_name: "athom-smart-plug-v2"
alias_name: "Athom Plug"
friendly_name: "Athom Smart Plug V2"
project_name: "athom.smart-plug-v2"
project_version: "1.1"
relay_restore_mode: RESTORE_DEFAULT_OFF

esphome:
name: "${device_name}"
friendly_name: ""
name_add_mac_suffix: true
project:
name: "${project_name}"
Expand Down Expand Up @@ -53,14 +52,14 @@ globals:

binary_sensor:
- platform: status
name: "Status"
name: "${friendly_name} Status"

- platform: gpio
pin:
number: 5
mode: INPUT_PULLUP
inverted: true
name: "Power Button"
name: "${friendly_name} Power Button"
disabled_by_default: true
on_multi_click:
- timing:
Expand All @@ -75,27 +74,27 @@ binary_sensor:

sensor:
- platform: uptime
name: "Uptime Sensor"
name: "${friendly_name} Uptime Sensor"

- platform: cse7766
update_interval: 10s
current:
name: "Current"
name: "${friendly_name} Current"
filters:
- lambda: if (x < 0.060) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected


voltage:
name: "Voltage"
name: "${friendly_name} Voltage"
power:
name: "Power"
name: "${friendly_name} Power"
id: power_sensor
filters:
- lambda: if (x < 3.0) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected


energy:
name: "Energy"
name: "${friendly_name} Energy"
id: energy
unit_of_measurement: kWh
filters:
Expand All @@ -110,7 +109,7 @@ sensor:
previous_energy_value = current_energy_value;
- platform: template
name: "Total Energy"
name: "${friendly_name} Total Energy"
unit_of_measurement: kWh
device_class: "energy"
state_class: "total_increasing"
Expand All @@ -121,7 +120,7 @@ sensor:
update_interval: 10s

- platform: total_daily_energy
name: "Total Daily Energy"
name: "${friendly_name} Total Daily Energy"
restore: true
power_id: power_sensor
unit_of_measurement: kWh
Expand All @@ -132,19 +131,23 @@ sensor:

button:
- platform: factory_reset
name: "Reset"
name: "Restart with Factory Default Settings"
id: Reset

- platform: safe_mode
name: "Safe Mode"
internal: false

switch:
- platform: gpio
name: "${alias_name}"
name: "${friendly_name}"
pin: GPIO12
id: relay
restore_mode: ${relay_restore_mode}

light:
- platform: status_led
name: "Status LED"
name: "${friendly_name} Status LED"
id: blue_led
disabled_by_default: true
pin:
Expand Down

4 comments on commit 1c1fd5b

@palves
Copy link

@palves palves commented on 1c1fd5b Mar 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"IP Address", "Connected SSID", "Mac Address", "Restart with Factory Default Settings", and "Safe Mode" are missing ${friendly_name}.

What's the plan for friendly_name going forward? Are you going to try removing it again? Where should one follow/discuss that?

@Roving-Ronin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would you need it....HA changed to automatically insert the name of the device into the entity ID.
If you added name: "${alias_name} Status LED" back in for example (can't use friendly_name as that is now an official variable in HA) it would mean you'd end up with a prefix of fridge_plug.fridge_plug.led for instance. We only needed this friendly name before, as under the older HA we would end up with duplicate entity names with a _1 or _2 etc suffix if had multiple plugs.
It also meant if we had to login to the ESPHome local device webserver everything would be prefixed with the friendly name... now none of that is required.

@palves
Copy link

@palves palves commented on 1c1fd5b Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Roving-Ronin read the commit and history a bit? This commit is re-adding the manually-added "${friendly_name} " prefix which had been removed from sensor names in a previous commit (ab76339), for the reasons you state. The reversion isn't fully complete, as it misses the ones that I pointed at. So we ended up worse than where we started.

@Roving-Ronin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@palves yes this latest commit makes ZERO sense. Just pull the unofficial athom friendly_name out from substitutions and replace with alias_name, and add the HA official friendly_name under esphome section in. As mentioned before, if people still want to be able to call a subsitution as they used too, then just call ${alias_name}.

Personally seen it simpler to just move to using my own yaml for these plugs. Example here for my dishwasher.

`
substitutions:
device_name: "gpo-dishwasher"
alias_name: "Dishwasher"
device_description: "Measure the energy consumption of the dishwasher"
set_timezone: "Australia/Sydney"
set_dns_domain: ".iot.home.lan"
project_name: "athom.smart-plug-v2"
project_version: "1.1 (Mod)"
relay_restore_mode: RESTORE_DEFAULT_ON

esphome:
name: "${device_name}"
friendly_name: "${alias_name}"
comment: '${device_description}'
name_add_mac_suffix: false
project:
name: "${project_name}"
version: "${project_version}"

esp8266:
board: esp8285
restore_from_flash: true

packages:
baseline: !include common/common_athom_plug_v2.yaml

api:

ota:

logger:
baud_rate: 0

mdns:
disabled: false

web_server:
port: 80

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
domain: "${set_dns_domain}"
fast_connect: true
ap: {} # This spawns an AP with the device name and mac address with no password.

captive_portal:
`

common_athom_plug_v2.yaml that is called being:

`
preferences:
flash_write_interval: 5min

uart:
rx_pin: RX
baud_rate: 4800

globals:

  • id: total_energy
    type: float
    restore_value: yes
    initial_value: '0.0'

binary_sensor:

  • platform: status
    name: "Device Status"
    entity_category: diagnostic

  • platform: gpio
    pin:
    number: 5
    mode: INPUT_PULLUP
    inverted: true
    name: "Power Button"
    disabled_by_default: true
    on_multi_click:

    • timing:
      • ON for at most 1s
      • OFF for at least 0.2s
        then:
      • switch.toggle: relay
    • timing:
      • ON for at least 4s
        then:
      • button.press: Reset
        internal: true

sensor:

  • platform: uptime
    name: "Uptime Seconds"
    id: uptime_seconds
    update_interval: 120s
    entity_category: diagnostic
    internal: True

  • platform: cse7766
    update_interval: 10s
    current:
    name: "Current"
    filters:
    - lambda: if (x < 0.060) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected

    voltage:
    name: "Voltage"
    power:
    name: "Power"
    id: power_sensor
    filters:
    - lambda: if (x < 3.0) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected

    energy:
    name: "Energy"
    id: energy
    unit_of_measurement: kWh
    filters:
    - multiply: 0.001
    on_value:
    then:
    - lambda: |-
    static float previous_energy_value = 0.0;
    float current_energy_value = id(energy).state;
    id(total_energy) += current_energy_value - previous_energy_value;
    previous_energy_value = current_energy_value;

  • platform: template
    name: "Energy Total"
    unit_of_measurement: kWh
    device_class: "energy"
    state_class: "total_increasing"
    icon: "mdi:lightning-bolt"
    accuracy_decimals: 3
    lambda: |-
    return id(total_energy);
    update_interval: 10s

  • platform: total_daily_energy
    name: "Energy Daily"
    restore: true
    power_id: power_sensor
    unit_of_measurement: kWh
    accuracy_decimals: 3
    filters:

    • multiply: 0.001

button:

  • platform: restart
    name: 'Restart Device'
    entity_category: diagnostic

  • platform: factory_reset
    name: Reset with Default Settings
    id: Reset

switch:

  • platform: gpio
    name: "Remote Control"
    pin: GPIO12
    id: relay
    restore_mode: ${relay_restore_mode}

light:

  • platform: status_led
    name: "Device Status LED"
    id: blue_led
    disabled_by_default: true
    pin:
    inverted: true
    number: GPIO13
    internal: true

text_sensor:

  • platform: template
    name: 'Device Last Restart'
    id: device_last_restart
    icon: mdi:clock
    entity_category: diagnostic

  • platform: wifi_info
    ip_address:
    name: 'WiFi IP Address'
    icon: mdi:wifi
    entity_category: diagnostic

    ssid:
    name: 'WiFi SSID'
    icon: mdi:wifi-strength-2
    entity_category: diagnostic

    mac_address:
    name: 'WiFi MAC Address'
    entity_category: diagnostic

  • platform: template
    name: 'Project Name'
    id: gas_meter_project
    icon: "mdi:label-outline"
    entity_category: diagnostic
    lambda: |-
    return {"${project_name}"};
    update_interval: 6h

  • platform: template
    name: 'Project Version'
    id: gas_meter_version
    icon: "mdi:label-outline"
    entity_category: diagnostic
    lambda: |-
    return {"${project_version}"};
    update_interval: 6h

  • platform: template
    name: "Device Uptime"
    entity_category: diagnostic
    lambda: |-
    int seconds = (id(uptime_seconds).state);
    int days = seconds / (24 * 3600);
    seconds = seconds % (24 * 3600);
    int hours = seconds / 3600;
    seconds = seconds % 3600;
    int minutes = seconds / 60;
    seconds = seconds % 60;
    if ( days > 3650 ) {
    return { "Starting up" };
    } else if ( days ) {
    return { (String(days) +"d " + String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
    } else if ( hours ) {
    return { (String(hours) +"h " + String(minutes) +"m "+ String(seconds) +"s").c_str() };
    } else if ( minutes ) {
    return { (String(minutes) +"m "+ String(seconds) +"s").c_str() };
    } else {
    return { (String(seconds) +"s").c_str() };
    }
    icon: mdi:clock-start

time:

  • platform: sntp
    id: sntp_time
    timezone: "${set_timezone}"
    update_interval: 360min
    servers:
    • 2.pool.ntp.org
    • 1.pool.ntp.org
    • 0.pool.ntp.org
      on_time_sync:
      then:
      • if:
        condition:
        lambda: 'return id(device_last_restart).state == "";'
        then:
        - text_sensor.template.publish:
        id: device_last_restart
        state: !lambda 'return id(sntp_time).now().strftime("%a %d %b %Y - %I:%M:%S %p");`

Ends up looking like this on device web interface:
image

Please sign in to comment.