General


El Tesla Model 3 sale más barato que un Dacia Sandero

Actualización 16/10/2024: El precio del Model 3 ha bajado de 37.970 € a 36.470 € y os dejo mi enlace de referido para ahorrar 1.000 € más y que os salga en 35.470 €.

Acabo de cambiar mi Citroën C3 con 20 años y 350.000 Km por un Tesla Model 3. A día de hoy comprarse un eléctrico es más barato que cualquier coche de combustión, siempre que dispongas de un garaje donde cargarlo por las noches. Cada vez que digo esto aún veo caras de incredulidad, así que voy a explicar mis cuentas.

Para ello vamos a compararlo con el coche más vendido en España, el Dacia Sandero, y con su versión más barata, un gasolina de 90 CV. Primero vamos a ver los precios de compra:

  • Dacia Sandero Essential TCe 90CV: 13.490 € (según su web)
  • Tesla Model 3 Standard Range 283CV: 35.470 € con mi enlace de referido

Son dos coches de gamas muy distintas y estamos comparando un coche de lujo contra un coche básico. En principio parece que el Model 3 es mucho más caro… no es así.

Primero las ayudas: Con el Model 3 obtienes una deducción en el IRPF de 3.000 € que cobrarás el siguiente año. Luego está el Moves III, que achatarrando tu anterior coche te van a devolver 7.500 € (o 4.500 € sin achatarrar). El Moves III se suele cobrar año y medio después, y ojo que del Moves se paga IRPF que depende de tu tramo de IRPF, pero vamos a asumir que devolvemos un 30%. Así el precio de compra del Model 3 quedaría en:

35.470 – 3.000 – 7.500 x 0,7 = 27.220 €

Por lo que pagamos 27.220 – 13.490 = 13.730 € más por el Model 3. ¿Es posible recuperarlos?

Vamos a ignorar mantenimiento, IVTM, etc. (que también son más baratos en el Model 3) para centrarnos sólo en el gran elefante en la habitación, el consumo en combustible.

Y vamos a usar datos de consumo WLTP (los reales serían más altos y por tanto más favorables al Model 3).

El Dacia consume 5,2 l / 100 km y el día que escribo esto la gasolina está a 1,549 € / l. Por lo tanto, hacer 100 km en el Dacia costaría:

5,2 l / 100 km x 1,549 € / l = 8,0548 € / 100 km

Con los eléctricos hay que acostumbrarse a usar los kWh (kilovatios hora). El consumo WLTP del Model 3 es de 13,2 kWh / 100 km. El precio del kWh depende mucho de donde carges.

Lo que le cuesta inicialmente comprender es que es muy fácil cargarlo en casa, sin necesidad de montar una Wallbox de 1.000 €, simplemente con el Mobile Connector de 200 €. Cargando en un enchufe schuko a 13 A se recuperan 19 km de autonomía por cada hora de carga. En 8 horas de carga por la noche (que es la duración del periodo de bajo coste P3 de la tarifa eléctrica, de 00:00h a 8:00h) se recuperan 152 km. Si no fueran suficientes sí que tendrías que instalar un Wallbox.

Planificándose para cargarlo por las noches en P3 con una tarifa como la Octopus 3 sale el kWh con IVA a:

0,084 x 1,21 = 0,10164 € / kWh

Y hacer 100 Km con el Tesla cuesta:

13,2 kWh / 100 km x 0,10164 € / kWh = 1,3416 € / 100 km

Yo me cambié a Octopus Energy al comprarme el coche eléctrico. Antes tenía una tarifa por la que pagaba el doble. Puedes pasarte a Octopus y ahorrarte 50 € adicionales con mi enlace de referido.

Resumiendo:

  • Dacia Sandero: 8,0548 € / 100 km
  • Tesla Model 3: 1,3416 € / 100 km

Y cuántos kilómetros necesitamos hacer para recuperar los 13.730 € de diferencia en el precio de compra:

13.730 / (8,0548 – 1,3416) x 100 = 204.522 km

Como os contaba, a mi anterior coche le hice más de 350.000 km. En mi caso comprar un eléctrico es un chollo.

Evidentemente la comparación sale mucho mejor contra un coche de su mismo segmento y características (pocos hay más baratos que el Model 3) y sale peor si usamos cargadores públicos (que en mi caso será de forma esporádica).

A día de hoy las únicas razones para no comprarse un eléctrico serían:

  • No tener garaje propio o el extraño caso de no poder instalar un enchufe en él.
  • No poder disponer del dinero para la inversión inicial. Es como una hipoteca inversa, pones el dinero inicialmente y lo vas recuperando mes a mes.
  • El también extraño caso de que la autonomía no sea suficiente.
  • Creerte alguno de los bulos que diariamente difunde sobre los coches eléctricos la agonizante industria del automóvil de combustión.

En mi caso me decidí por el Model 3 pero también entiendo que no es coche para todo el mundo. Es muy largo (4,7 m) y requiere estar familiarizado con pantallas táctiles. A lo mejor puedes necesitar más espacio e irte a por un Model Y. El Model 3 SR a día de hoy sigue siendo el eléctrico más eficiente del mercado según https://ev-database.org A nivel tecnológico está una década por delante de las marcas tradicionales. Algunas calidades están rateadas (como la pintura…) pero a mi parecer sigue siendo el coche más disruptivo de este siglo.

Os dejo mi enlace de referido, por si queréis ahorraros 1.000 € euros más al comprarlo:

https://www.tesla.com/referral/alberto770619


ESPHome in a RTL8710BX smart plug

I bought from a popular chinese store a generic Tuya smart plug with power monitoring. It was extrememly cheap, costing less than 4 EUR. And of course I bought it to play trying to flash ESPHome.

The first challenge was to open it without breaking it. I was able to open it by wrapping it in cardboard and gently tapping it with a hammer around the body.

You never know what chip you are going to find. In the past ESP8266 was very common but now they switched mainly to Beken chips. This smart switch has a T102_V1.1 board with a Realtek RTL8710BX chip:

Luckily the support for this chip was developed in the LibreTiny project:

https://github.com/libretiny-eu/libretiny

And now it’s integrated into ESPHome:

https://esphome.io/components/libretiny

This is the board:

https://fcc.report/FCC-ID/2AU7O-T102V11/4540736.pdf

And after investigating the outputs, I reached this conclusion about them:

IndexRTL8710BXConnection
1VDDConnected
3GNDConnected
5GPIO_A18/UART0_RXDConnected to the button
7GPIO_A23/UART0_TXDNot connected
9GPIO_A14/PWM0 Power Monitor SEL pin
11GPIO_A15/PWM1Connected to the relay
2 GPIO_A12/PWM3Power monitor CF1 pin
4GPIO_A0/PWM2Power monitor CF pin
6GPIO_A5/PWM4Status LED inverted (there is another LED connected to the relay)
8GPIO_A30/DEBUG_LOG_TXNot connected, I soldered a cable to the flasher RX
10GPIO_A29/DEBUG_LOG_RXNot connected, I soldered a cable to the flasher TX

ESPHome

I created one device this config in the ESPHome dashboard (without power monitoring, read below if you want to enable it):

substitutions:
  devicename: smartplug1
  friendly_name: Smart Plug 1

esphome:
  name: ${devicename}
  friendly_name: ${friendly_name}

rtl87xx:
  board: wr2
  framework:
    version: 1.5.1

logger:

api:
  password: ""

ota:
  password: ""

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

  ap:
    ssid: ${friendly_name} Fallback Hotspot
    password: !secret wifi_password

captive_portal:

web_server:
  port: 80

status_led:
  pin:
    number: PA5
    inverted: true

text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version

sensor:
  - platform: uptime
    name: Uptime
    filters:
      - lambda: return x / 60.0;
    unit_of_measurement: minutes

  - platform: wifi_signal
    name: Wifi Signal
    update_interval: 60s

binary_sensor:
  - platform: gpio
    device_class: power
    name: Button
    pin:
      number: PA18
      mode: INPUT_PULLUP
      inverted: true
    on_press:
      - switch.toggle: relay

switch:
  - platform: gpio
    id: relay
    name: ${friendly_name}
    pin: PA15
    restore_mode: RESTORE_DEFAULT_OFF

There is currently an open bug in LibreTiny and with the board t102-v1.1 the PA15 output does not work, so I needed to use the board wr2 on line 10.

I built it from the ESPHome dashboard and downloaded a .uf2 file.

Connecting an USB UART to the chip

I soldered four dupont cables to VDD, GND, GPIO_A29 and GPIO_A30 connecting them to an FTDI232 USB UART:

While connected to the FTDI232, the log from the chip can be viewed, i.e. with minicom (but remember to disable hardware flow control):

minicom -D /dev/ttyUSB0 -b 115200

Flashing

The official flashing guide does not recomment to power the chip with the USB flasher, but it worked for me:

https://docs.libretiny.eu/docs/platform/realtek-ambz/#flashing

You need the ltchiptool tool, I installed it in a Python virtualenv:

python3 -m venv .
source bin/activate
pip install ltchiptool zeroconf

The ltchiptool GUI caused some segmentation fault, so I used it from the commmand line.

To put the chip in flash mode, we need to power it with the TX pin connected to GND.

In flash mode, I created a backup of the previous firmware:

ltchiptool flash read realtek-ambz flash-backup.bin

And to write the ESPHome firmware:

ltchiptool flash write smartplug1.uf2


After the flashing, if I try to power it from USB the WiFi module did not start and it causes a boot loop, but It worked perfectly plugging it into the mains power. A new device appeared in the router and I can connect to the ESPHome web dashboard.

Adding power metering

The plug includes a power metering chip: the BL0936, that is supported by ESPHome:

https://esphome.io/components/sensor/hlw8012.html

However, after configuring and uploading the firmware with the power meter enabled to the board, the device enters a boot loop, displaying the following error:

[D][switch:016]: 'Smart Plug 1' Turning OFF.
[D][binary_sensor:034]: 'Button': Sending initial state OFF
[C][hlw8012:014]: Setting up HLW8012...
W [      0.109] CHANGE interrupts not supported

Luckily, after 10 reboots, the firmware enters in the “OTA safe mode”, disabling all the modules and connecting to the WiFi without the web dashboard but opening a port to allow remote flashing.

https://esphome.io/components/ota.html

It is a problem in the combination of the RTL8710 chip and the BL0936 module, there is an open issue about this:

https://github.com/libretiny-eu/libretiny/issues/155

It can be fixed with the workaround of SuperXL2023 modifying the .esphome/platformio/platforms/libretiny/cores/realtek-amb/arduino/src/wiring_irq.c file and adding the lines 64 and 65:

62: #if LT_RTL8720C
63:                        event = IRQ_FALL_RISE;
64: #elif LT_RTL8710B
65:                        event = IRQ_RISE;
66: #else
67:                        LT_W("CHANGE interrupts not supported !!!!!!");

In the ESPHome config I’m specifying the version of the framework to avoid losing this fix in an automatic update. It works perfectly after rebuilding the image with this fix and uploading it to the device.

This is the complete ESPHome configuration with power metering:

substitutions:
  devicename: smartplug1
  friendly_name: Smart Plug 1

  voltage_divider: "1400"
  current_resistor: "0.001"
  current_multiply: "1.0"

esphome:
  name: ${devicename}
  friendly_name: ${friendly_name}

rtl87xx:
  board: wr2
  framework:
    version: 1.5.1

logger:

api:
  password: ""

ota:
  password: ""

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

  ap:
    ssid: ${friendly_name} Fallback Hotspot
    password: !secret wifi_password

captive_portal:

web_server:
  port: 80

status_led:
  pin:
    number: PA5
    inverted: true

text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version

sensor:
  - platform: uptime
    name: Uptime
    filters:
      - lambda: return x / 60.0;
    unit_of_measurement: minutes

  - platform: wifi_signal
    name: Wifi Signal
    update_interval: 60s

  - platform: hlw8012
    model: BL0937
    sel_pin:
      number: PA14
      inverted: true
    cf_pin:
      number: PA0
    cf1_pin:
      number: PA12

    current:
      name: Current
      filters:
        - multiply: ${current_multiply}
    voltage:
      name: Voltage
    power:
      name: Power
    energy:
      name: Energy

    update_interval: 30s
    current_resistor: ${current_resistor}
    voltage_divider: ${voltage_divider}

binary_sensor:
  - platform: gpio
    device_class: power
    name: Button
    pin:
      number: PA18
      mode: INPUT_PULLUP
      inverted: true
    on_press:
      - switch.toggle: relay

switch:
  - platform: gpio
    id: relay
    name: ${friendly_name}
    pin: PA15
    restore_mode: RESTORE_DEFAULT_OFF

It needs to calibrate the sensor to obtain the proper values of voltage_divider, current_resistor and current_multiply. It can be done with a multimeter and entering the values in the hlw8012 page.


Avatar and stereoscopic 3D screens

Now that the new Avatar movie was released, it’s time to remember what happened when the first Avatar was released in 2009: It unleashed a craze about stereoscopic 3D movies & TVs.

2010 was declared “The year of 3D TV”. Somehow it was assumed that we were going to watch TV with glasses. I remember “experts” saying ‘In the future all the TVs will be 3D”.

I went to the cinema a couple times to watch 3D movies, and at the begining it was fun to try, but I got bored soon. I also bought a TV without 3D.

There was a lack of 3D content, and some movies where converted to 3D with algorithms producing a mediocre result. Also 3D viewing was causing headaches in a lot of people.

Nintendo joined the trend in 2011 launching the 3DS, that was showing 3D without glasses. But almost everybody was using it with the 3D deactivated, and in 2013 they launched the 2DS, without the 3D.

The production of 3D TVs ended in 2016 putting an end to this trend.

I remember this every time that someone says we are going to use VR headsets for work. Glasses, stereoscopic view, trends, headaches…


Coding in the Dark Side (with Eclipse!)

screenshotGetting back to the old days where I used Emacs to code (ok, more than ten years ago), now I’m using a dark theme in Eclipse. Dark themes are less eye-stressing and now are becoming popular with editors like IntelliJ, Sublime Text and the last Visual Studio. And that’s why more people is learning to programming even to his difficulty, although there are strategies that people can use to improve their learning, so you can use all the power of your mind to learn, you could visit http://www.subconsciousmindpowertechniques.com/ to find out more about this.

The Eclipse Juno platform supports styling of the SWT widgets via CSS, but many other elements must be setup manually, so I published my CSS and setup instructions in a GitHub repository: https://github.com/albertoruibal/eclipse_dark_css

Welcome to the dark side!


My Favourite HTML5 APIs

Ok, I’m supossed to be an Android developer, but i’m going back to HTML+JS for some projects, and I found that HTML5 has really powerful new APIS, these are my favourite:

  1. WebGL: Is changing the game rules, finally advanced 3D graphics in the browser. As it’s very hard to use directly,  I suggest the Three.js library
  2. Storage: A very simple system so store data in the browser, much more powerful than cookies
  3. Web Workers: Multithreading in Javascript, yes, now it’s possible
  4. WebAudio: a good sound API for the web, continues having some differences between browsers, but promises to be great

And I am already using this APIs in some Mobialia web apps:

App WebGL Storage Web Workers WebAudio
Mobialia Chess 3D X X X  
Slot Racing X X   X
Four in a Row X X    

This apps are developed in Java with Google Web Toolkit (GWT), you can also view  my slides: Migrating apps from Android to HTML5 via GWT. I also want to recommend the P4rgaming site, which has been one of my favorites when it comes down to getting gaming services for my video games. When it comes to playing WoW, you might find it hard to build up a sustainable sum of money. In the past for BFA and Legion i was using sites like 6Kgold and others like G2, now i simply hop off to Gold4Vanilla for all my warcraft gold needs.


Mobialia en Canal TEA

Esta semana invitáronme a participar nun programa da televisión local de Ponteareas (Canal TEA). Falamos un pouco dos fundamentos de Android, das aplicacións de Mobialia, tablets, MiFis etc. Foi unha experiencia moi interesante e a primeira vez que vou a unha canle de Televisión.


My London travel tips

This easter we were on London, it was a great experience and I want to share with you some travel tips:

AIRPORT

I arrived to Stansted Airport. Try to get a fligth to Heatrow or Gatwick. Stansted is 1 hour away by bus from London city center.

There are many bus companies from Stansted to London, the cheapest and fastest is Terravision (15£ with return, 14£ if you book online) but National Express (9£ single) has free WiFi.

CURRENCY

There are many currency exchange offices, but the best is to get cash on an ATM with you credit card. If your bank charges a small comission (ING Direct charges only 2.5%), is cheaper than the exchange offices.

BUS & UNDERGROUND

The city is divided into zones, all the city center is zone 1-2. You can get a “Day Travelcard” for zones 1-2 by 6.60£ (cheap compared to the 4£ of a single travel). You can buy it on the automatic machines at the entries of the tube (allows payment with credit card).

This travelcard also allows you to use the city bus on this zones (only showing the card to the driver). A great tip is to get the bus line 11, you will get a sightseeing arround the touristic zones by the price of a Day Travelcard.

CYCLE HIRE

One funny thing that you can do is to hire a bicycle on one of the many points along the city. You can do it with your credit card. First you must pay 1£ for the access to the cycle hire for 24 hours. Then, you get a cycle by obtaining a printed release code from the machine. This code is composed of “1”, “2” and “3” digits that you must type on the cycle dock to release it.

When you dock the cycle again the system charges you card with an amount depending of the time that you used the cycle. One hour costs 1£ and the prices lower as you use it more hours. By only 2£ you can get a cycle by one hour.

MUSEUMS

The British Museum and other public museums are free so don’t miss them. Quite curious that you can’t take photos with flash on the underground but the British Museum is full of unconscious tourists taking photos with flash and touching pieces from the ancient Egypt.

WIFI

It’s quite hard to find free WiFis on London, but there are lot of BT-FON spots, my advice is to became a FON member before traveling to London, buy “La Fonera” by only 39€ at http://www.fon.com and share your home ADSL. As a FON member you can use this WiFis for free.

HOTELS

We were on a Easyhotel room but I can only say that it was cheap. Easyhotel thinks that a “room with window” is an underground room with a window to a corridor without natural light. It’s also quite surprising to make fit a bed and a bathroom on 6m2.


Using two location providers on Android


Android has two kinds of accuracy on location:

  • Fine: provided by the GPS, needs some time to be obtained
  • Coarse: location determined with the cell of the mobile network

This location methods can be enabled or disabled by the user on the preferences or with some widgets.

Initially on our apps we used only one LocationProvider with “Fine” accuracy:

  • If the GPS was disabled it used automatically network-based location
  • But if GPS was enabled, the location used it needing some time to be determined

As the data couldn’t be obtained until the location is determined, the app didn’t showed data, receiving this kind of error reports from some users.

The best solution that I found is to mantain two separated providers, with different precisions and receive location updates using both.

LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
criteria.setPowerRequirement(Criteria.POWER_LOW);       

criteria.setAccuracy(Criteria.ACCURACY_FINE);
String providerFine = manager.getBestProvider(criteria, true);

criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String providerCoarse = manager.getBestProvider(criteria, true);

if (providerCoarse != null) {
    manager.requestLocationUpdates(providerCoarse, 5*60000, 100, this);
}
if (providerFine != null) {
    manager.requestLocationUpdates(providerFine, 5*60000, 100, this);
}

You can also check if providerFine and providerCoarse are the same provider. When receiving location, the one received from providerFine must take precedence over the one from providerCoarse. Location’s provider can be obtained with location.getProvider():

public void onLocationChanged(Location location) {
     if (location.getProvider().equals(providerFine)) {
     ...

This is a trick that we are using on our Gas Stations Spain app and also on Wikiplaces (open sourced).


Find Android apps with AppBrain

One of the first things that you can notice after buying an android phone is the great amount of mobile applications (apps) that you can download from the Android Market, but searching for a specific app can be very frustating, and a time-consuming task.

This is due to one of the biggest problems of the Android Market: the lack of a complete web interface to query the applications avaiable, and AppBrain is an independent web (not affiliated with Google) where you can list, search, etc. those apps.

There are many similar webs: Cyrket, Bubiloop, but Appbrain has some features which make the difference:

  • You can sign-in on the web with your Google account
  • Apps can be queried by country, genre (of the user), age range, etc.
  • You can create list of apps and share it with your friends
  • There is an android app (search for AppBrain on the Android Market) to synchronize your mobile with appbrain, and once installed:
  • You can query the installed apps on your mobile
  • You can install apps from the web

And everything with a very simple and pretty interface, so don’t wait to try it:

http://www.appbrain.com